任务包的相关代码

master
土豆兄弟 4 years ago
parent 4a15b262b0
commit 1f9e4808fe

@ -0,0 +1,96 @@
/*
* 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.taskrecord.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 javax.persistence.Entity;
import javax.persistence.Table;
import org.hibernate.annotations.*;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://el-admin.vip
* @description /
* @author x
* @date 2020-09-08
**/
@Entity
@Data
@Table(name="tb_task_record")
public class TaskRecord implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
@ApiModelProperty(value = "id")
private Integer id;
@Column(name = "gmt_create")
@CreationTimestamp
@ApiModelProperty(value = "创建时间")
private Timestamp gmtCreate;
@Column(name = "gmt_modified")
@UpdateTimestamp
@ApiModelProperty(value = "修改时间")
private Timestamp gmtModified;
@Column(name = "task_name")
@ApiModelProperty(value = "任务名称")
private String taskName;
@Column(name = "time_period",nullable = false)
@NotNull
@ApiModelProperty(value = "任务保存周期")
private Integer timePeriod;
@Column(name = "is_build",nullable = false)
@NotNull
@ApiModelProperty(value = "任务是否建立成功")
private Integer isBuild;
@Column(name = "is_send",nullable = false)
@NotNull
@ApiModelProperty(value = "发送状态记录")
private Integer isSend;
@Column(name = "opration_name")
@ApiModelProperty(value = "操作人")
private String oprationName;
@Column(name = "desc",nullable = false)
@NotBlank
@ApiModelProperty(value = "自定义内容补充")
private String desc;
@Column(name = "local_file_path")
@ApiModelProperty(value = "本地生成待发送文件路径")
private String localFilePath;
@Column(name = "params")
@ApiModelProperty(value = "查询参数暂存")
private String params;
public void copy(TaskRecord 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.taskrecord.repository;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @website https://el-admin.vip
* @author x
* @date 2020-09-08
**/
public interface TaskRecordRepository extends JpaRepository<TaskRecord, Integer>, JpaSpecificationExecutor<TaskRecord> {
}

@ -0,0 +1,108 @@
/*
* 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.taskrecord.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.abmessage.rest.vo.AbMessageVO;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import me.zhengjie.modules.taskrecord.service.TaskRecordService;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordQueryCriteria;
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 x
* @date 2020-09-08
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "taskRecord管理")
@RequestMapping("/api/taskRecord")
public class TaskRecordController {
private final TaskRecordService taskRecordService;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('taskRecord:list')")
public void download(HttpServletResponse response, TaskRecordQueryCriteria criteria) throws IOException {
taskRecordService.download(taskRecordService.queryAll(criteria), response);
}
@GetMapping
@Log("查询taskRecord")
@ApiOperation("查询taskRecord")
@PreAuthorize("@el.check('taskRecord:list')")
public ResponseEntity<Object> query(TaskRecordQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(taskRecordService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping
@Log("新增taskRecord")
@ApiOperation("新增taskRecord")
@PreAuthorize("@el.check('taskRecord:add')")
public ResponseEntity<Object> create(@Validated @RequestBody TaskRecord resources){
return new ResponseEntity<>(taskRecordService.create(resources),HttpStatus.CREATED);
}
@PutMapping
@Log("修改taskRecord")
@ApiOperation("修改taskRecord")
@PreAuthorize("@el.check('taskRecord:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody TaskRecord resources){
taskRecordService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除taskRecord")
@ApiOperation("删除taskRecord")
@PreAuthorize("@el.check('taskRecord:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Integer[] ids) {
taskRecordService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
// ================ 自定义功能实现 start ================
@Log("发送课包任务")
@ApiOperation("ABMessage发送任务")
@PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/sendTask")
public ResponseEntity<Object> sendTask(@Validated @RequestBody TaskRecord resources){
// TODO: 2020/9/8 0008 发送任务在相关逻辑类中实现
return new ResponseEntity<>(HttpStatus.OK);
}
@Log("任务课包任务合并")
@ApiOperation("任务课包任务合并")
@PreAuthorize("@el.check('taskRecord:list')")
@PostMapping(value = "/mergeRecord")
public ResponseEntity<Object> mergeRecord(@RequestBody Integer[] ids){
// TODO: 2020/9/8 0008 发送任务在相关逻辑类中实现
return new ResponseEntity<>(HttpStatus.OK);
}
// ================ 自定义功能实现 end ================
}

@ -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.taskrecord.service;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordDto;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordQueryCriteria;
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 x
* @date 2020-09-08
**/
public interface TaskRecordService {
/**
*
* @param criteria
* @param pageable
* @return Map<String,Object>
*/
Map<String,Object> queryAll(TaskRecordQueryCriteria criteria, Pageable pageable);
/**
*
* @param criteria
* @return List<TaskRecordDto>
*/
List<TaskRecordDto> queryAll(TaskRecordQueryCriteria criteria);
/**
* ID
* @param id ID
* @return TaskRecordDto
*/
TaskRecordDto findById(Integer id);
/**
*
* @param resources /
* @return TaskRecordDto
*/
TaskRecordDto create(TaskRecord resources);
/**
*
* @param resources /
*/
void update(TaskRecord resources);
/**
*
* @param ids /
*/
void deleteAll(Integer[] ids);
/**
*
* @param all
* @param response /
* @throws IOException /
*/
void download(List<TaskRecordDto> all, HttpServletResponse response) throws IOException;
}

@ -0,0 +1,63 @@
/*
* 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.taskrecord.service.dto;
import lombok.Data;
import java.sql.Timestamp;
import java.io.Serializable;
/**
* @website https://el-admin.vip
* @description /
* @author x
* @date 2020-09-08
**/
@Data
public class TaskRecordDto implements Serializable {
/** id */
private Integer id;
/** 创建时间 */
private Timestamp gmtCreate;
/** 修改时间 */
private Timestamp gmtModified;
/** 任务名称 */
private String taskName;
/** 任务保存周期 */
private Integer timePeriod;
/** 任务是否建立成功 */
private Integer isBuild;
/** 发送状态记录 */
private Integer isSend;
/** 操作人 */
private String oprationName;
/** 自定义内容补充 */
private String desc;
/** 本地生成待发送文件路径 */
private String localFilePath;
/** 查询参数暂存 */
private String params;
}

@ -0,0 +1,49 @@
/*
* 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.taskrecord.service.dto;
import lombok.Data;
import java.util.List;
import me.zhengjie.annotation.Query;
/**
* @website https://el-admin.vip
* @author x
* @date 2020-09-08
**/
@Data
public class TaskRecordQueryCriteria{
/** 精确 */
@Query
private String taskName;
/** 精确 */
@Query
private Integer timePeriod;
/** 精确 */
@Query
private Integer isBuild;
/** 精确 */
@Query
private Integer isSend;
/** 精确 */
@Query
private String oprationName;
}

@ -0,0 +1,113 @@
/*
* 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.taskrecord.service.impl;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.taskrecord.repository.TaskRecordRepository;
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.modules.taskrecord.service.mapstruct.TaskRecordMapper;
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 x
* @date 2020-09-08
**/
@Service
@RequiredArgsConstructor
public class TaskRecordServiceImpl implements TaskRecordService {
private final TaskRecordRepository taskRecordRepository;
private final TaskRecordMapper taskRecordMapper;
@Override
public Map<String,Object> queryAll(TaskRecordQueryCriteria criteria, Pageable pageable){
Page<TaskRecord> page = taskRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(taskRecordMapper::toDto));
}
@Override
public List<TaskRecordDto> queryAll(TaskRecordQueryCriteria criteria){
return taskRecordMapper.toDto(taskRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
@Transactional
public TaskRecordDto findById(Integer id) {
TaskRecord taskRecord = taskRecordRepository.findById(id).orElseGet(TaskRecord::new);
ValidationUtil.isNull(taskRecord.getId(),"TaskRecord","id",id);
return taskRecordMapper.toDto(taskRecord);
}
@Override
@Transactional(rollbackFor = Exception.class)
public TaskRecordDto create(TaskRecord resources) {
return taskRecordMapper.toDto(taskRecordRepository.save(resources));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TaskRecord resources) {
TaskRecord taskRecord = taskRecordRepository.findById(resources.getId()).orElseGet(TaskRecord::new);
ValidationUtil.isNull( taskRecord.getId(),"TaskRecord","id",resources.getId());
taskRecord.copy(resources);
taskRecordRepository.save(taskRecord);
}
@Override
public void deleteAll(Integer[] ids) {
for (Integer id : ids) {
taskRecordRepository.deleteById(id);
}
}
@Override
public void download(List<TaskRecordDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (TaskRecordDto taskRecord : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("创建时间", taskRecord.getGmtCreate());
map.put("修改时间", taskRecord.getGmtModified());
map.put("任务名称", taskRecord.getTaskName());
map.put("任务保存周期", taskRecord.getTimePeriod());
map.put("任务是否建立成功", taskRecord.getIsBuild());
map.put("发送状态记录", taskRecord.getIsSend());
map.put("操作人", taskRecord.getOprationName());
map.put("自定义内容补充", taskRecord.getDesc());
map.put("本地生成待发送文件路径", taskRecord.getLocalFilePath());
map.put("查询参数暂存", taskRecord.getParams());
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.taskrecord.service.mapstruct;
import me.zhengjie.base.BaseMapper;
import me.zhengjie.modules.taskrecord.domain.TaskRecord;
import me.zhengjie.modules.taskrecord.service.dto.TaskRecordDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @website https://el-admin.vip
* @author x
* @date 2020-09-08
**/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface TaskRecordMapper extends BaseMapper<TaskRecordDto, TaskRecord> {
}
Loading…
Cancel
Save