From 0af908b25b7547ebf1612ca4db77d23123e1b005 Mon Sep 17 00:00:00 2001 From: chenken <3108545897@qq.com> Date: Mon, 14 Sep 2020 09:58:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=80=E5=8F=B7=E5=BA=93=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buildrecord/domain/BuildRecord.java | 95 +++++++++++++++ .../repository/BuildRecordRepository.java | 28 +++++ .../rest/BuildRecordController.java | 87 +++++++++++++ .../service/BuildRecordService.java | 83 +++++++++++++ .../service/dto/BuildRecordDto.java | 69 +++++++++++ .../service/dto/BuildRecordQueryCriteria.java | 29 +++++ .../service/impl/BuildRecordServiceImpl.java | 115 ++++++++++++++++++ .../service/mapstruct/BuildRecordMapper.java | 32 +++++ 8 files changed, 538 insertions(+) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/domain/BuildRecord.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/repository/BuildRecordRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/rest/BuildRecordController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/BuildRecordService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/dto/BuildRecordDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/dto/BuildRecordQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/impl/BuildRecordServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/mapstruct/BuildRecordMapper.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/domain/BuildRecord.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/domain/BuildRecord.java new file mode 100644 index 0000000..aaefb75 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/domain/BuildRecord.java @@ -0,0 +1,95 @@ +/* +* 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.buildrecord.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 java.sql.Timestamp; +import java.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-10 +**/ +@Entity +@Data +@Table(name="tb_build_record") +public class BuildRecord implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + @ApiModelProperty(value = "id") + private Integer id; + + @Column(name = "gmt_create") + @ApiModelProperty(value = "创建时间") + private Timestamp gmtCreate; + + @Column(name = "gmt_modified") + @ApiModelProperty(value = "修改时间") + private Timestamp gmtModified; + + @Column(name = "task_name") + @ApiModelProperty(value = "任务名称") + private String taskName; + + @Column(name = "time_period") + @ApiModelProperty(value = "任务保存周期") + private Integer timePeriod; + + @Column(name = "is_build") + @ApiModelProperty(value = "任务是否建立成功") + private Integer isBuild; + + @Column(name = "is_send") + @ApiModelProperty(value = "发送状态记录") + private Integer isSend; + + @Column(name = "opration_name") + @ApiModelProperty(value = "操作人") + private String oprationName; + + @Column(name = "description") + @ApiModelProperty(value = "自定义内容补充") + private String description; + + @Column(name = "local_file_path") + @ApiModelProperty(value = "本地生成待发送文件路径") + private String localFilePath; + + @Column(name = "params") + @ApiModelProperty(value = "查询参数暂存") + private String params; + + @Column(name = "total") + @ApiModelProperty(value = "该任务生成总记录数") + private Long total; + + @Column(name = "send_total") + @ApiModelProperty(value = "上次发送总记录数") + private Long sendTotal; + + public void copy(BuildRecord 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/buildrecord/repository/BuildRecordRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/repository/BuildRecordRepository.java new file mode 100644 index 0000000..778d546 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/repository/BuildRecordRepository.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.buildrecord.repository; + +import me.zhengjie.modules.buildrecord.domain.BuildRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-10 +**/ +public interface BuildRecordRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/rest/BuildRecordController.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/rest/BuildRecordController.java new file mode 100644 index 0000000..02a89c0 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/rest/BuildRecordController.java @@ -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.buildrecord.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.buildrecord.domain.BuildRecord; +import me.zhengjie.modules.buildrecord.service.BuildRecordService; +import me.zhengjie.modules.buildrecord.service.dto.BuildRecordQueryCriteria; +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-10 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "buildRecord管理") +@RequestMapping("/api/buildRecord") +public class BuildRecordController { + + private final BuildRecordService buildRecordService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('buildRecord:list')") + public void download(HttpServletResponse response, BuildRecordQueryCriteria criteria) throws IOException { + buildRecordService.download(buildRecordService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询buildRecord") + @ApiOperation("查询buildRecord") + @PreAuthorize("@el.check('buildRecord:list')") + public ResponseEntity query(BuildRecordQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(buildRecordService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增buildRecord") + @ApiOperation("新增buildRecord") + @PreAuthorize("@el.check('buildRecord:add')") + public ResponseEntity create(@Validated @RequestBody BuildRecord resources){ + return new ResponseEntity<>(buildRecordService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改buildRecord") + @ApiOperation("修改buildRecord") + @PreAuthorize("@el.check('buildRecord:edit')") + public ResponseEntity update(@Validated @RequestBody BuildRecord resources){ + buildRecordService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除buildRecord") + @ApiOperation("删除buildRecord") + @PreAuthorize("@el.check('buildRecord:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody Integer[] ids) { + buildRecordService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/BuildRecordService.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/BuildRecordService.java new file mode 100644 index 0000000..352ad82 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/BuildRecordService.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.buildrecord.service; + +import me.zhengjie.modules.buildrecord.domain.BuildRecord; +import me.zhengjie.modules.buildrecord.service.dto.BuildRecordDto; +import me.zhengjie.modules.buildrecord.service.dto.BuildRecordQueryCriteria; +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-10 +**/ +public interface BuildRecordService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(BuildRecordQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(BuildRecordQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return BuildRecordDto + */ + BuildRecordDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return BuildRecordDto + */ + BuildRecordDto create(BuildRecord resources); + + /** + * 编辑 + * @param resources / + */ + void update(BuildRecord 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/buildrecord/service/dto/BuildRecordDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/dto/BuildRecordDto.java new file mode 100644 index 0000000..227312d --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/dto/BuildRecordDto.java @@ -0,0 +1,69 @@ +/* +* 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.buildrecord.service.dto; + +import lombok.Data; +import java.sql.Timestamp; +import java.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-10 +**/ +@Data +public class BuildRecordDto 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 description; + + /** 本地生成待发送文件路径 */ + private String localFilePath; + + /** 查询参数暂存 */ + private String params; + + /** 该任务生成总记录数 */ + private Long total; + + /** 上次发送总记录数 */ + private Long sendTotal; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/dto/BuildRecordQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/dto/BuildRecordQueryCriteria.java new file mode 100644 index 0000000..9d338e5 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/dto/BuildRecordQueryCriteria.java @@ -0,0 +1,29 @@ +/* +* 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.buildrecord.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-10 +**/ +@Data +public class BuildRecordQueryCriteria{ +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/impl/BuildRecordServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/impl/BuildRecordServiceImpl.java new file mode 100644 index 0000000..0e84c34 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/impl/BuildRecordServiceImpl.java @@ -0,0 +1,115 @@ +/* +* 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.buildrecord.service.impl; + +import me.zhengjie.modules.buildrecord.domain.BuildRecord; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.buildrecord.repository.BuildRecordRepository; +import me.zhengjie.modules.buildrecord.service.BuildRecordService; +import me.zhengjie.modules.buildrecord.service.dto.BuildRecordDto; +import me.zhengjie.modules.buildrecord.service.dto.BuildRecordQueryCriteria; +import me.zhengjie.modules.buildrecord.service.mapstruct.BuildRecordMapper; +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-10 +**/ +@Service +@RequiredArgsConstructor +public class BuildRecordServiceImpl implements BuildRecordService { + + private final BuildRecordRepository buildRecordRepository; + private final BuildRecordMapper buildRecordMapper; + + @Override + public Map queryAll(BuildRecordQueryCriteria criteria, Pageable pageable){ + Page page = buildRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(buildRecordMapper::toDto)); + } + + @Override + public List queryAll(BuildRecordQueryCriteria criteria){ + return buildRecordMapper.toDto(buildRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public BuildRecordDto findById(Integer id) { + BuildRecord buildRecord = buildRecordRepository.findById(id).orElseGet(BuildRecord::new); + ValidationUtil.isNull(buildRecord.getId(),"BuildRecord","id",id); + return buildRecordMapper.toDto(buildRecord); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public BuildRecordDto create(BuildRecord resources) { + return buildRecordMapper.toDto(buildRecordRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(BuildRecord resources) { + BuildRecord buildRecord = buildRecordRepository.findById(resources.getId()).orElseGet(BuildRecord::new); + ValidationUtil.isNull( buildRecord.getId(),"BuildRecord","id",resources.getId()); + buildRecord.copy(resources); + buildRecordRepository.save(buildRecord); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + buildRecordRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (BuildRecordDto buildRecord : all) { + Map map = new LinkedHashMap<>(); + map.put("创建时间", buildRecord.getGmtCreate()); + map.put("修改时间", buildRecord.getGmtModified()); + map.put("任务名称", buildRecord.getTaskName()); + map.put("任务保存周期", buildRecord.getTimePeriod()); + map.put("任务是否建立成功", buildRecord.getIsBuild()); + map.put("发送状态记录", buildRecord.getIsSend()); + map.put("操作人", buildRecord.getOprationName()); + map.put("自定义内容补充", buildRecord.getDescription()); + map.put("本地生成待发送文件路径", buildRecord.getLocalFilePath()); + map.put("查询参数暂存", buildRecord.getParams()); + map.put("该任务生成总记录数", buildRecord.getTotal()); + map.put("上次发送总记录数", buildRecord.getSendTotal()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/mapstruct/BuildRecordMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/mapstruct/BuildRecordMapper.java new file mode 100644 index 0000000..dc7dfea --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/buildrecord/service/mapstruct/BuildRecordMapper.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.buildrecord.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.buildrecord.domain.BuildRecord; +import me.zhengjie.modules.buildrecord.service.dto.BuildRecordDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-10 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface BuildRecordMapper extends BaseMapper { + +} \ No newline at end of file