diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/domain/TaskRecord.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/domain/TaskRecord.java new file mode 100644 index 0000000..159e351 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/domain/TaskRecord.java @@ -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)); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/repository/TaskRecordRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/repository/TaskRecordRepository.java new file mode 100644 index 0000000..f8a1b67 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/repository/TaskRecordRepository.java @@ -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, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/rest/TaskRecordController.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/rest/TaskRecordController.java new file mode 100644 index 0000000..b8f8a18 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/rest/TaskRecordController.java @@ -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 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 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 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 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 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 mergeRecord(@RequestBody Integer[] ids){ + // TODO: 2020/9/8 0008 发送任务在相关逻辑类中实现 + return new ResponseEntity<>(HttpStatus.OK); + } + // ================ 自定义功能实现 end ================ +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/TaskRecordService.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/TaskRecordService.java new file mode 100644 index 0000000..0e5e447 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/TaskRecordService.java @@ -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 + */ + Map queryAll(TaskRecordQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List 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 all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/dto/TaskRecordDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/dto/TaskRecordDto.java new file mode 100644 index 0000000..922b8bb --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/dto/TaskRecordDto.java @@ -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; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/dto/TaskRecordQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/dto/TaskRecordQueryCriteria.java new file mode 100644 index 0000000..cb05ef4 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/dto/TaskRecordQueryCriteria.java @@ -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; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/impl/TaskRecordServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/impl/TaskRecordServiceImpl.java new file mode 100644 index 0000000..f0d5e7f --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/impl/TaskRecordServiceImpl.java @@ -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 queryAll(TaskRecordQueryCriteria criteria, Pageable pageable){ + Page page = taskRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(taskRecordMapper::toDto)); + } + + @Override + public List 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 all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TaskRecordDto taskRecord : all) { + Map 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); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/mapstruct/TaskRecordMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/mapstruct/TaskRecordMapper.java new file mode 100644 index 0000000..115e2c4 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/taskrecord/service/mapstruct/TaskRecordMapper.java @@ -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 { + +} \ No newline at end of file