From 38b7eb8a371154ea3ee916814601a1119e30c288 Mon Sep 17 00:00:00 2001 From: qyx <565485304@qq.com> Date: Fri, 16 Oct 2020 17:32:51 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E4=B8=8A=E4=BC=A0=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../me/zhengjie/modules/edu/domain/Edu.java | 58 +++++ .../modules/edu/repository/EduRepository.java | 78 +++++++ .../modules/edu/rest/EduController.java | 87 +++++++ .../modules/edu/service/EduService.java | 107 +++++++++ .../modules/edu/service/dto/EduDto.java | 37 +++ .../edu/service/dto/EduQueryCriteria.java | 45 ++++ .../edu/service/impl/EduServiceImpl.java | 168 ++++++++++++++ .../edu/service/mapstruct/EduMapper.java | 32 +++ .../modules/school/domain/School.java | 65 ++++++ .../school/repository/SchoolRepository.java | 28 +++ .../modules/school/rest/SchoolController.java | 87 +++++++ .../modules/school/service/SchoolService.java | 83 +++++++ .../modules/school/service/dto/SchoolDto.java | 41 ++++ .../service/dto/SchoolQueryCriteria.java | 49 ++++ .../service/impl/SchoolServiceImpl.java | 108 +++++++++ .../service/mapstruct/SchoolMapper.java | 32 +++ .../me/zhengjie/modules/tag/domain/Tag.java | 58 +++++ .../modules/tag/repository/TagRepository.java | 28 +++ .../modules/tag/rest/TagController.java | 87 +++++++ .../modules/tag/service/TagService.java | 119 ++++++++++ .../modules/tag/service/dto/TagDto.java | 37 +++ .../tag/service/dto/TagQueryCriteria.java | 45 ++++ .../tag/service/impl/TagServiceImpl.java | 213 ++++++++++++++++++ .../tag/service/mapstruct/TagMapper.java | 32 +++ .../tmpfilerecord/domain/TempFileRecord.java | 69 ++++++ .../repository/TempFileRecordRepository.java | 30 +++ .../rest/TempFileRecordController.java | 97 ++++++++ .../service/TempFileRecordService.java | 92 ++++++++ .../service/dto/TempFileRecordDto.java | 47 ++++ .../dto/TempFileRecordQueryCriteria.java | 49 ++++ .../impl/TempFileRecordServiceImpl.java | 119 ++++++++++ .../mapstruct/TempFileRecordMapper.java | 32 +++ 32 files changed, 2259 insertions(+) create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/domain/Edu.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/repository/EduRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/rest/EduController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/service/EduService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/service/impl/EduServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/edu/service/mapstruct/EduMapper.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/domain/School.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/repository/SchoolRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/rest/SchoolController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/service/SchoolService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/service/dto/SchoolDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/service/dto/SchoolQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/service/impl/SchoolServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/school/service/mapstruct/SchoolMapper.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/domain/Tag.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/repository/TagRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/rest/TagController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/service/TagService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/service/impl/TagServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tag/service/mapstruct/TagMapper.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/repository/TempFileRecordRepository.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java create mode 100644 eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/mapstruct/TempFileRecordMapper.java diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/edu/domain/Edu.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/domain/Edu.java new file mode 100644 index 0000000..ae7a34e --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/domain/Edu.java @@ -0,0 +1,58 @@ +/* +* 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.edu.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.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-21 +**/ +@Entity +@Data +@Table(name="dc_edu") +public class Edu implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + @ApiModelProperty(value = "id") + private Long id; + + @Column(name = "uid") + @ApiModelProperty(value = "uid") + private String uid; + + @Column(name = "mid") + @ApiModelProperty(value = "mid") + private Integer mid; + + @Column(name = "level") + @ApiModelProperty(value = "level") + private Integer level; + + public void copy(Edu 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/edu/repository/EduRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/repository/EduRepository.java new file mode 100644 index 0000000..e4ef11c --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/repository/EduRepository.java @@ -0,0 +1,78 @@ +/* +* 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.edu.repository; + +import me.zhengjie.modules.edu.domain.Edu; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-21 +**/ +public interface EduRepository extends JpaRepository, JpaSpecificationExecutor { + + /** + * 根据坐标进行查询 + * + * @param cityCode 城市id集合 + * @param stuGrade 年级集合 + * @param minX 精度最小值 + * @param maxX 精度最大值 + * @param minY 维度最小值 + * @param maxY 维度最大值 + * @return 查询到的uid列表 + */ + @Query(value = "SELECT e.uid FROM dc_school s JOIN dc_edu e ON s.oldid = e.mid " + + "WHERE 1=1 "+ + "AND (coalesce (:stuGrade , null) is null or e.level IN ( :stuGrade )) " + + "AND (coalesce (:cityCode , null) is null or s.city_code IN ( :cityCode)) " + + "AND IF(:minX IS NOT NULL,s.lng BETWEEN :minX AND :maxX AND s.lat BETWEEN :minY AND :maxY, 1=1)", nativeQuery = true) + Slice findAllMatchDataByPage(@Param("cityCode") List cityCode, + @Param("stuGrade") List stuGrade, + @Param("minX") Double minX, + @Param("maxX") Double maxX, + @Param("minY") Double minY, + @Param("maxY") Double maxY, + Pageable pageable); + + + /** + * 统计总数 + * + * @param cityCode + * @param stuGrade + * @param minX + * @param maxX + * @param minY + * @param maxY + * @return + */ + @Query(value = "SELECT count(e.uid) FROM dc_school s JOIN dc_edu e ON s.oldid = e.mid " + + "WHERE 1=1 "+ + "AND (coalesce (:stuGrade , null) is null or e.level IN ( :stuGrade )) " + + "AND (coalesce (:cityCode , null) is null or s.city_code IN ( :cityCode)) " + + "AND IF(:minX IS NOT NULL,s.lng BETWEEN :minX AND :maxX AND s.lat BETWEEN :minY AND :maxY, 1=1)", nativeQuery = true) + long countMatchData(List cityCode, List stuGrade, Double minX, Double maxX, Double minY, Double maxY); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/edu/rest/EduController.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/rest/EduController.java new file mode 100644 index 0000000..86500dd --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/rest/EduController.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.edu.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.edu.domain.Edu; +import me.zhengjie.modules.edu.service.EduService; +import me.zhengjie.modules.edu.service.dto.EduQueryCriteria; +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-21 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "Edu管理") +@RequestMapping("/api/edu") +public class EduController { + + private final EduService eduService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('edu:list')") + public void download(HttpServletResponse response, EduQueryCriteria criteria) throws IOException { + eduService.download(eduService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询Edu") + @ApiOperation("查询Edu") + @PreAuthorize("@el.check('edu:list')") + public ResponseEntity query(EduQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(eduService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增Edu") + @ApiOperation("新增Edu") + @PreAuthorize("@el.check('edu:add')") + public ResponseEntity create(@Validated @RequestBody Edu resources){ + return new ResponseEntity<>(eduService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改Edu") + @ApiOperation("修改Edu") + @PreAuthorize("@el.check('edu:edit')") + public ResponseEntity update(@Validated @RequestBody Edu resources){ + eduService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除Edu") + @ApiOperation("删除Edu") + @PreAuthorize("@el.check('edu:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody Long[] ids) { + eduService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/EduService.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/EduService.java new file mode 100644 index 0000000..f30fdae --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/EduService.java @@ -0,0 +1,107 @@ +/* +* 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.edu.service; + +import com.spatial4j.core.shape.Rectangle; +import me.zhengjie.modules.edu.domain.Edu; +import me.zhengjie.modules.edu.service.dto.EduDto; +import me.zhengjie.modules.edu.service.dto.EduQueryCriteria; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Slice; + +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-21 +**/ +public interface EduService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(EduQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(EduQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return EduDto + */ + EduDto findById(Long id); + + /** + * 创建 + * @param resources / + * @return EduDto + */ + EduDto create(Edu resources); + + /** + * 编辑 + * @param resources / + */ + void update(Edu resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Long[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; + + + /** + * 两表条件关联查出需要的发送uid,然后保存在发送表中 + * + * @param cityCode + * @param stuGrade + * @param rectangle + */ + Slice queryMatchData(List cityCode, List stuGrade, Rectangle rectangle, Pageable pageable); + + /** + * 计算总数 + * + * @param cities + * @param grades + * @param rectangle + * @return + */ + long countMatchData(List cities, List grades, Rectangle rectangle); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduDto.java new file mode 100644 index 0000000..ff41641 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduDto.java @@ -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.edu.service.dto; + +import lombok.Data; +import java.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-21 +**/ +@Data +public class EduDto implements Serializable { + + private Long id; + + private String uid; + + private Integer mid; + + private Integer level; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduQueryCriteria.java new file mode 100644 index 0000000..b587992 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/dto/EduQueryCriteria.java @@ -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.edu.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-21 +**/ +@Data +public class EduQueryCriteria{ + + /** 精确 */ + @Query + private Long id; + + /** 精确 */ + @Query + private String uid; + + /** 精确 */ + @Query + private Integer mid; + + /** 精确 */ + @Query + private Integer level; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/impl/EduServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/impl/EduServiceImpl.java new file mode 100644 index 0000000..8e73910 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/impl/EduServiceImpl.java @@ -0,0 +1,168 @@ +/* +* 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.edu.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.spatial4j.core.shape.Rectangle; +import lombok.extern.slf4j.Slf4j; +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.edu.domain.Edu; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.edu.repository.EduRepository; +import me.zhengjie.modules.edu.service.EduService; +import me.zhengjie.modules.edu.service.dto.EduDto; +import me.zhengjie.modules.edu.service.dto.EduQueryCriteria; +import me.zhengjie.modules.edu.service.mapstruct.EduMapper; +import org.springframework.data.domain.Slice; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +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 org.springframework.util.CollectionUtils; + +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-21 +**/ +@Service +@RequiredArgsConstructor +@Slf4j +public class EduServiceImpl implements EduService { + + private final EduRepository eduRepository; + private final EduMapper eduMapper; + + @Override + public Map queryAll(EduQueryCriteria criteria, Pageable pageable){ + Page page = eduRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(eduMapper::toDto)); + } + + @Override + public List queryAll(EduQueryCriteria criteria){ + return eduMapper.toDto(eduRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public EduDto findById(Long id) { + Edu edu = eduRepository.findById(id).orElseGet(Edu::new); + ValidationUtil.isNull(edu.getId(),"Edu","id",id); + return eduMapper.toDto(edu); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public EduDto create(Edu resources) { + return eduMapper.toDto(eduRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Edu resources) { + Edu edu = eduRepository.findById(resources.getId()).orElseGet(Edu::new); + ValidationUtil.isNull( edu.getId(),"Edu","id",resources.getId()); + edu.copy(resources); + eduRepository.save(edu); + } + + @Override + public void deleteAll(Long[] ids) { + for (Long id : ids) { + eduRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (EduDto edu : all) { + Map map = new LinkedHashMap<>(); + map.put(" uid", edu.getUid()); + map.put(" mid", edu.getMid()); + map.put(" level", edu.getLevel()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + @Transactional(propagation= Propagation.REQUIRED) + public Slice queryMatchData(List cityCode, List stuGrade, Rectangle rectangle, Pageable pageable) { + // 经度范围 + Double minX = null; + Double maxX = null; + // 纬度范围 + Double minY = null; + Double maxY = null; + if (rectangle != null){ + // 获取所有的范围坐标点 + // 经度范围 + minX = rectangle.getMinX(); + maxX = rectangle.getMaxX(); + // 纬度范围 + minY = rectangle.getMinY(); + maxY = rectangle.getMaxY(); + } + + // 先进行查询 + Slice matchDataList = eduRepository.findAllMatchDataByPage(cityCode, stuGrade, minX, maxX, minY, maxY, pageable); + // 对数据进行保存入库 + if (CollectionUtil.isEmpty(matchDataList)){ + log.warn("========== [query data is Empty,please check !!] =========="); + return null; + } + return matchDataList; + } + + @Override + @Deprecated + public long countMatchData(List cityCode, List stuGrade, Rectangle rectangle) { + // 获取所有的范围坐标点 + // 经度范围 + Double minX = null; + Double maxX = null; + // 纬度范围 + Double minY = null; + Double maxY = null; + if (rectangle != null){ + // 获取所有的范围坐标点 + // 经度范围 + minX = rectangle.getMinX(); + maxX = rectangle.getMaxX(); + // 纬度范围 + minY = rectangle.getMinY(); + maxY = rectangle.getMaxY(); + } + + // 先进行查询 + return eduRepository.countMatchData(cityCode, stuGrade, minX, maxX, minY, maxY); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/mapstruct/EduMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/mapstruct/EduMapper.java new file mode 100644 index 0000000..4adac13 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/edu/service/mapstruct/EduMapper.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.edu.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.edu.domain.Edu; +import me.zhengjie.modules.edu.service.dto.EduDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-21 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface EduMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/school/domain/School.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/domain/School.java new file mode 100644 index 0000000..ab6113e --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/domain/School.java @@ -0,0 +1,65 @@ +/* +* 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.school.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 java.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-21 +**/ +@Entity +@Data +@Table(name="dc_school") +public class School implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + @ApiModelProperty(value = "id") + private Long id; + + @Column(name = "oldid") + @ApiModelProperty(value = "oldid") + private Integer oldid; + + @Column(name = "city_code") + @ApiModelProperty(value = "cityCode") + private Integer cityCode; + + @Column(name = "lng") + @ApiModelProperty(value = "lng") + private String lng; + + @Column(name = "lat") + @ApiModelProperty(value = "lat") + private String lat; + + @Column(name = "type") + @ApiModelProperty(value = "type") + private Integer type; + + public void copy(School 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/school/repository/SchoolRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/repository/SchoolRepository.java new file mode 100644 index 0000000..72b7b72 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/repository/SchoolRepository.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.school.repository; + +import me.zhengjie.modules.school.domain.School; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-21 +**/ +public interface SchoolRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/school/rest/SchoolController.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/rest/SchoolController.java new file mode 100644 index 0000000..40f1388 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/rest/SchoolController.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.school.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.school.domain.School; +import me.zhengjie.modules.school.service.SchoolService; +import me.zhengjie.modules.school.service.dto.SchoolQueryCriteria; +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-21 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "School管理") +@RequestMapping("/api/school") +public class SchoolController { + + private final SchoolService schoolService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('school:list')") + public void download(HttpServletResponse response, SchoolQueryCriteria criteria) throws IOException { + schoolService.download(schoolService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询School") + @ApiOperation("查询School") + @PreAuthorize("@el.check('school:list')") + public ResponseEntity query(SchoolQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(schoolService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增School") + @ApiOperation("新增School") + @PreAuthorize("@el.check('school:add')") + public ResponseEntity create(@Validated @RequestBody School resources){ + return new ResponseEntity<>(schoolService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改School") + @ApiOperation("修改School") + @PreAuthorize("@el.check('school:edit')") + public ResponseEntity update(@Validated @RequestBody School resources){ + schoolService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除School") + @ApiOperation("删除School") + @PreAuthorize("@el.check('school:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody Long[] ids) { + schoolService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/school/service/SchoolService.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/SchoolService.java new file mode 100644 index 0000000..ddbb31e --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/SchoolService.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.school.service; + +import me.zhengjie.modules.school.domain.School; +import me.zhengjie.modules.school.service.dto.SchoolDto; +import me.zhengjie.modules.school.service.dto.SchoolQueryCriteria; +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-21 +**/ +public interface SchoolService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(SchoolQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(SchoolQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return SchoolDto + */ + SchoolDto findById(Long id); + + /** + * 创建 + * @param resources / + * @return SchoolDto + */ + SchoolDto create(School resources); + + /** + * 编辑 + * @param resources / + */ + void update(School resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Long[] 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/school/service/dto/SchoolDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/dto/SchoolDto.java new file mode 100644 index 0000000..e528f51 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/dto/SchoolDto.java @@ -0,0 +1,41 @@ +/* +* 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.school.service.dto; + +import lombok.Data; +import java.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-21 +**/ +@Data +public class SchoolDto implements Serializable { + + private Long id; + + private Integer oldid; + + private Integer cityCode; + + private String lng; + + private String lat; + + private Integer type; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/school/service/dto/SchoolQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/dto/SchoolQueryCriteria.java new file mode 100644 index 0000000..c7ae7e0 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/dto/SchoolQueryCriteria.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.school.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-21 +**/ +@Data +public class SchoolQueryCriteria{ + + /** 精确 */ + @Query + private Long id; + + /** 精确 */ + @Query + private Integer oldid; + + /** 精确 */ + @Query + private Integer cityCode; + + /** 精确 */ + @Query + private String lng; + + /** 精确 */ + @Query + private Integer type; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/school/service/impl/SchoolServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/impl/SchoolServiceImpl.java new file mode 100644 index 0000000..7ef058a --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/impl/SchoolServiceImpl.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.school.service.impl; + +import me.zhengjie.modules.school.domain.School; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.school.repository.SchoolRepository; +import me.zhengjie.modules.school.service.SchoolService; +import me.zhengjie.modules.school.service.dto.SchoolDto; +import me.zhengjie.modules.school.service.dto.SchoolQueryCriteria; +import me.zhengjie.modules.school.service.mapstruct.SchoolMapper; +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-21 +**/ +@Service +@RequiredArgsConstructor +public class SchoolServiceImpl implements SchoolService { + + private final SchoolRepository schoolRepository; + private final SchoolMapper schoolMapper; + + @Override + public Map queryAll(SchoolQueryCriteria criteria, Pageable pageable){ + Page page = schoolRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(schoolMapper::toDto)); + } + + @Override + public List queryAll(SchoolQueryCriteria criteria){ + return schoolMapper.toDto(schoolRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public SchoolDto findById(Long id) { + School school = schoolRepository.findById(id).orElseGet(School::new); + ValidationUtil.isNull(school.getId(),"School","id",id); + return schoolMapper.toDto(school); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public SchoolDto create(School resources) { + return schoolMapper.toDto(schoolRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(School resources) { + School school = schoolRepository.findById(resources.getId()).orElseGet(School::new); + ValidationUtil.isNull( school.getId(),"School","id",resources.getId()); + school.copy(resources); + schoolRepository.save(school); + } + + @Override + public void deleteAll(Long[] ids) { + for (Long id : ids) { + schoolRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (SchoolDto school : all) { + Map map = new LinkedHashMap<>(); + map.put(" oldid", school.getOldid()); + map.put(" cityCode", school.getCityCode()); + map.put(" lng", school.getLng()); + map.put(" lat", school.getLat()); + map.put(" type", school.getType()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/school/service/mapstruct/SchoolMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/mapstruct/SchoolMapper.java new file mode 100644 index 0000000..87eda49 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/school/service/mapstruct/SchoolMapper.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.school.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.school.domain.School; +import me.zhengjie.modules.school.service.dto.SchoolDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-21 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface SchoolMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tag/domain/Tag.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/domain/Tag.java new file mode 100644 index 0000000..fe01e02 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/domain/Tag.java @@ -0,0 +1,58 @@ +/* +* 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.tag.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.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-22 +**/ +@Entity +@Data +@Table(name="dc_tag") +public class Tag implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + @ApiModelProperty(value = "id") + private Long id; + + @Column(name = "uid") + @ApiModelProperty(value = "uid") + private String uid; + + @Column(name = "task_id") + @ApiModelProperty(value = "taskId") + private Long taskId; + + @Column(name = "push_status") + @ApiModelProperty(value = "pushStatus") + private Integer pushStatus; + + public void copy(Tag 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/tag/repository/TagRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/repository/TagRepository.java new file mode 100644 index 0000000..4a231b3 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/repository/TagRepository.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.tag.repository; + +import me.zhengjie.modules.tag.domain.Tag; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-22 +**/ +public interface TagRepository extends JpaRepository, JpaSpecificationExecutor { +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tag/rest/TagController.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/rest/TagController.java new file mode 100644 index 0000000..7c64713 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/rest/TagController.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.tag.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.tag.domain.Tag; +import me.zhengjie.modules.tag.service.TagService; +import me.zhengjie.modules.tag.service.dto.TagQueryCriteria; +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-22 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "Tag管理") +@RequestMapping("/api/tag") +public class TagController { + + private final TagService tagService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tag:list')") + public void download(HttpServletResponse response, TagQueryCriteria criteria) throws IOException { + tagService.download(tagService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询Tag") + @ApiOperation("查询Tag") + @PreAuthorize("@el.check('tag:list')") + public ResponseEntity query(TagQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tagService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增Tag") + @ApiOperation("新增Tag") + @PreAuthorize("@el.check('tag:add')") + public ResponseEntity create(@Validated @RequestBody Tag resources){ + return new ResponseEntity<>(tagService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改Tag") + @ApiOperation("修改Tag") + @PreAuthorize("@el.check('tag:edit')") + public ResponseEntity update(@Validated @RequestBody Tag resources){ + tagService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除Tag") + @ApiOperation("删除Tag") + @PreAuthorize("@el.check('tag:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody Long[] ids) { + tagService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/TagService.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/TagService.java new file mode 100644 index 0000000..bcdeeb9 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/TagService.java @@ -0,0 +1,119 @@ +/* +* 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.tag.service; + +import com.spatial4j.core.shape.Rectangle; +import me.zhengjie.modules.tag.domain.Tag; +import me.zhengjie.modules.tag.service.dto.TagDto; +import me.zhengjie.modules.tag.service.dto.TagQueryCriteria; +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-22 +**/ +public interface TagService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TagQueryCriteria criteria, Pageable pageable); + + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + List queryAllBySlice(TagQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TagQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TagDto + */ + TagDto findById(Long id); + + /** + * 创建 + * @param resources / + * @return TagDto + */ + TagDto create(Tag resources); + + /** + * 编辑 + * @param resources / + */ + void update(Tag resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Long[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; + + /** + * 保存 + * + * @param collect + * @return + */ + Integer saveAll(List collect); + + /** + * 批量更新分表状态 + * + * @param pushIds + * @param taskId + * @return + */ + Integer updateAllPushStatus(List pushIds, Long taskId); + + /** + * 按条件进行查询并批量插入 + * + * @param cityCode + * @param stuGrade + * @param rectangle + */ + Integer queryAndBatchInsertData(Integer taskId,List cityCode, List stuGrade, Rectangle rectangle); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagDto.java new file mode 100644 index 0000000..d522c03 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagDto.java @@ -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.tag.service.dto; + +import lombok.Data; +import java.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author x +* @date 2020-09-22 +**/ +@Data +public class TagDto implements Serializable { + + private Long id; + + private String uid; + + private Long taskId; + + private Integer pushStatus; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagQueryCriteria.java new file mode 100644 index 0000000..6d60554 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/dto/TagQueryCriteria.java @@ -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.tag.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-22 +**/ +@Data +public class TagQueryCriteria{ + + /** 精确 */ + @Query + private Long id; + + /** 精确 */ + @Query + private String uid; + + /** 精确 */ + @Query + private Long taskId; + + /** 精确 */ + @Query + private Integer pushStatus; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/impl/TagServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/impl/TagServiceImpl.java new file mode 100644 index 0000000..1c3f904 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/impl/TagServiceImpl.java @@ -0,0 +1,213 @@ +/* +* 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.tag.service.impl; + +import cn.hutool.core.collection.CollectionUtil; +import com.spatial4j.core.shape.Rectangle; +import me.zhengjie.modules.student.domain.Student; +import me.zhengjie.modules.tag.domain.Tag; +import me.zhengjie.utils.*; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.tag.repository.TagRepository; +import me.zhengjie.modules.tag.service.TagService; +import me.zhengjie.modules.tag.service.dto.TagDto; +import me.zhengjie.modules.tag.service.dto.TagQueryCriteria; +import me.zhengjie.modules.tag.service.mapstruct.TagMapper; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.data.domain.Slice; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.jdbc.core.BatchPreparedStatementSetter; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.util.CollectionUtils; + +import java.math.BigInteger; +import java.sql.PreparedStatement; +import java.sql.SQLException; +import java.util.*; +import java.io.IOException; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import javax.persistence.TemporalType; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://el-admin.vip +* @description 服务实现 +* @author x +* @date 2020-09-22 +**/ +@Service +@RequiredArgsConstructor +public class TagServiceImpl implements TagService { + + @Value("${tag.split-table.sum}") + private Integer tableSum; + + private final TagRepository tagRepository; + private final TagMapper tagMapper; + + @PersistenceContext + private EntityManager entityManager; + + @Override + public Map queryAll(TagQueryCriteria criteria, Pageable pageable){ + Page page = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tagMapper::toDto)); + } + + @Override + public List queryAllBySlice(TagQueryCriteria criteria, Pageable pageable) { + Slice slice = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return slice.getContent(); + } + + @Override + public List queryAll(TagQueryCriteria criteria){ + return tagMapper.toDto(tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TagDto findById(Long id) { + Tag tag = tagRepository.findById(id).orElseGet(Tag::new); + ValidationUtil.isNull(tag.getId(),"Tag","id",id); + return tagMapper.toDto(tag); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TagDto create(Tag resources) { + return tagMapper.toDto(tagRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(Tag resources) { + Tag tag = tagRepository.findById(resources.getId()).orElseGet(Tag::new); + ValidationUtil.isNull( tag.getId(),"Tag","id",resources.getId()); + tag.copy(resources); + tagRepository.save(tag); + } + + @Override + public void deleteAll(Long[] ids) { + for (Long id : ids) { + tagRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TagDto tag : all) { + Map map = new LinkedHashMap<>(); + map.put(" uid", tag.getUid()); + map.put(" taskId", tag.getTaskId()); + map.put(" pushStatus", tag.getPushStatus()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public Integer saveAll(List collect) { + if (CollectionUtils.isEmpty(collect)){ + return 0; + } + List tagList= tagRepository.saveAll(collect); + if (CollectionUtils.isEmpty(tagList)){ + return 0; + } + return tagList.size(); + } + + /** + * 自定义拼接sql实现数据的插入 + * + * @param cityCode + * @param stuGrade + * @param rectangle + */ + @Override + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + public Integer queryAndBatchInsertData(Integer taskId, List cityCode, List stuGrade, Rectangle rectangle) { + // 设置复杂sql语句 + StringBuilder insertSql = new StringBuilder(); + insertSql.append("INSERT INTO dc_tag") + .append(taskId % tableSum) // 分表序号 + .append(" (uid, task_id, push_status) SELECT e.uid, ") + .append(taskId) + .append(", 0 FROM dc_school s JOIN dc_edu e ON s.oldid = e.mid "); + // 拼接where条件 + StringBuilder whereSql = new StringBuilder(" WHERE 1 = 1"); + // 年级 + if (CollectionUtil.isNotEmpty(stuGrade)) { + whereSql.append(" AND e.level IN (:stuGrade)"); + } + // 城市ID + if (CollectionUtil.isNotEmpty(cityCode)) { + whereSql.append(" AND s.city_code IN (:cityCode)"); + } + + // 坐标 + if (Objects.nonNull(rectangle)){ + whereSql.append(" AND s.lng >= :minX AND s.lng < :maxX AND s.lat >= :minY AND s.lat < :maxY "); + } + // 拼接成完整sql + insertSql.append(whereSql); + // 拼接乱序 + insertSql.append(" ORDER BY RAND()"); + //创建本地sql查询实例 + Query dataQuery = entityManager.createNativeQuery(insertSql.toString()); + // 设置参数 + if (CollectionUtil.isNotEmpty(stuGrade)){ + dataQuery.setParameter("stuGrade", stuGrade); + } + if (CollectionUtil.isNotEmpty(cityCode)){ + dataQuery.setParameter("cityCode", cityCode); + } + if (Objects.nonNull(rectangle)){ + // 经度范围 + dataQuery.setParameter("minX", rectangle.getMinX()); + dataQuery.setParameter("maxX", rectangle.getMaxX()); + // 纬度范围 + dataQuery.setParameter("minY", rectangle.getMinY()); + dataQuery.setParameter("maxY", rectangle.getMaxY()); + } + // 返回执行结果 + return dataQuery.executeUpdate(); + } + + + @Override + @Transactional(readOnly = false, propagation = Propagation.REQUIRED) + @Modifying + public Integer updateAllPushStatus(List pushIds, Long taskId) { + String sql = "update dc_tag d set d.push_status = 1 where d.task_id = :taskId and d.id in ( :pushIds )"; + + Query nativeQuery = entityManager.createNativeQuery(sql); + nativeQuery.setParameter("taskId", taskId); + nativeQuery.setParameter("pushIds", pushIds); + + return nativeQuery.executeUpdate(); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/mapstruct/TagMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/mapstruct/TagMapper.java new file mode 100644 index 0000000..f61d3c7 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tag/service/mapstruct/TagMapper.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.tag.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.tag.domain.Tag; +import me.zhengjie.modules.tag.service.dto.TagDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://el-admin.vip +* @author x +* @date 2020-09-22 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TagMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.java new file mode 100644 index 0000000..954ec1f --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/domain/TempFileRecord.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.tmpfilerecord.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.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author X +* @date 2020-10-15 +**/ +@Entity +@Data +@Table(name="tb_temp_file_record") +public class TempFileRecord implements Serializable { + + @Id + @Column(name = "id") + @ApiModelProperty(value = "id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(name = "ip_addrs") + @ApiModelProperty(value = "访问接口的ip地址记录") + private String ipAddrs; + + @Column(name = "file_paths") + @ApiModelProperty(value = "文件生成地址") + private String filePaths; + + @Column(name = "verification_code") + @ApiModelProperty(value = "访问文件验证码") + private String verificationCode; + + @Column(name = "days") + @ApiModelProperty(value = "有效保存时间") + private Integer days; + + /** + * ,0-未下载,1-已下载,2-已删除 + */ + @Column(name = "file_status") + @ApiModelProperty(value = "文件保存状态") + private Integer fileStatus; + + public void copy(TempFileRecord 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/tmpfilerecord/repository/TempFileRecordRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/repository/TempFileRecordRepository.java new file mode 100644 index 0000000..06d5fc6 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/repository/TempFileRecordRepository.java @@ -0,0 +1,30 @@ +/* +* 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.tmpfilerecord.repository; + +import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** +* @website https://el-admin.vip +* @author X +* @date 2020-10-15 +**/ +public interface TempFileRecordRepository extends JpaRepository, JpaSpecificationExecutor { + + TempFileRecord findByVerificationCodeAndFileStatus(String verificationCode, Integer fileStatus); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java new file mode 100644 index 0000000..091588e --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/rest/TempFileRecordController.java @@ -0,0 +1,97 @@ +/* +* 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.tmpfilerecord.rest; + +import cn.hutool.json.JSON; +import cn.hutool.json.JSONUtil; +import me.zhengjie.annotation.Log; +import me.zhengjie.common.http.CommonResponse; +import me.zhengjie.common.http.ResponseCode; +import me.zhengjie.common.json.OnceLinkMsgJsonContent; +import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; +import me.zhengjie.modules.tmpfilerecord.service.TempFileRecordService; +import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; +import me.zhengjie.service.EmailService; +import me.zhengjie.utils.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +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 org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://el-admin.vip +* @author X +* @date 2020-10-15 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "tmpfilerecord管理") +@RequestMapping("/api/tempFileRecord") +public class TempFileRecordController { + + private final TempFileRecordService tempFileRecordService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tempFileRecord:list')") + public void download(HttpServletResponse response, TempFileRecordQueryCriteria criteria) throws IOException { + tempFileRecordService.download(tempFileRecordService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询tmpfilerecord") + @ApiOperation("查询tmpfilerecord") + @PreAuthorize("@el.check('tempFileRecord:list')") + public ResponseEntity query(TempFileRecordQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tempFileRecordService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增tmpfilerecord") + @ApiOperation("新增tmpfilerecord") + @PreAuthorize("@el.check('tempFileRecord:add')") + public ResponseEntity create(@Validated @RequestBody TempFileRecord resources){ + return new ResponseEntity<>(tempFileRecordService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改tmpfilerecord") + @ApiOperation("修改tmpfilerecord") + @PreAuthorize("@el.check('tempFileRecord:edit')") + public ResponseEntity update(@Validated @RequestBody TempFileRecord resources){ + tempFileRecordService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Log("删除tmpfilerecord") + @ApiOperation("删除tmpfilerecord") + @PreAuthorize("@el.check('tempFileRecord:del')") + @DeleteMapping + public ResponseEntity delete(@RequestBody Integer[] ids) { + tempFileRecordService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java new file mode 100644 index 0000000..2c5cd27 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/TempFileRecordService.java @@ -0,0 +1,92 @@ +/* +* 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.tmpfilerecord.service; + +import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; +import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto; +import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; +import org.springframework.data.domain.Pageable; +import org.springframework.web.multipart.MultipartFile; + +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-10-15 +**/ +public interface TempFileRecordService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TempFileRecordQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TempFileRecordDto + */ + TempFileRecordDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return TempFileRecordDto + */ + TempFileRecordDto create(TempFileRecord resources); + + /** + * 编辑 + * @param resources / + */ + void update(TempFileRecord resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Integer[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; + + + /** + * 根据文件访问验证码进行访问 + */ + TempFileRecord findByVerificationCode(String verificationCode, Integer fileStatus); + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java new file mode 100644 index 0000000..512b5b2 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordDto.java @@ -0,0 +1,47 @@ +/* +* 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.tmpfilerecord.service.dto; + +import lombok.Data; +import java.io.Serializable; + +/** +* @website https://el-admin.vip +* @description / +* @author X +* @date 2020-10-15 +**/ +@Data +public class TempFileRecordDto implements Serializable { + + /** id */ + private Integer id; + + /** 访问接口的ip地址记录 */ + private String ipAddrs; + + /** 文件生成地址 */ + private String filePaths; + + /** 访问文件验证码 */ + private String verificationCode; + + /** 有效保存时间 */ + private Integer days; + + /** 文件保存状态 */ + private Integer fileStatus; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.java new file mode 100644 index 0000000..e5c07b9 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/dto/TempFileRecordQueryCriteria.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.tmpfilerecord.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://el-admin.vip +* @author X +* @date 2020-10-15 +**/ +@Data +public class TempFileRecordQueryCriteria{ + + /** 精确 */ + @Query + private Integer id; + + /** 精确 */ + @Query + private String ipAddrs; + + /** 精确 */ + @Query + private String verificationCode; + + /** 精确 */ + @Query + private Integer days; + + /** 精确 */ + @Query + private Integer fileStatus; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java new file mode 100644 index 0000000..4e2e577 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/impl/TempFileRecordServiceImpl.java @@ -0,0 +1,119 @@ +/* +* 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.tmpfilerecord.service.impl; + +import cn.hutool.core.util.RandomUtil; +import cn.hutool.system.OsInfo; +import cn.hutool.system.SystemUtil; +import lombok.extern.slf4j.Slf4j; +import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; +import me.zhengjie.utils.*; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.tmpfilerecord.repository.TempFileRecordRepository; +import me.zhengjie.modules.tmpfilerecord.service.TempFileRecordService; +import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto; +import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordQueryCriteria; +import me.zhengjie.modules.tmpfilerecord.service.mapstruct.TempFileRecordMapper; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.web.multipart.MultipartFile; + +import java.nio.file.Paths; +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-10-15 +**/ +@Service +@RequiredArgsConstructor +@Slf4j +public class TempFileRecordServiceImpl implements TempFileRecordService { + + private final TempFileRecordRepository tempFileRecordRepository; + private final TempFileRecordMapper tempFileRecordMapper; + + @Override + public Map queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable){ + Page page = tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tempFileRecordMapper::toDto)); + } + + @Override + public List queryAll(TempFileRecordQueryCriteria criteria){ + return tempFileRecordMapper.toDto(tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TempFileRecordDto findById(Integer id) { + TempFileRecord tempFileRecord = tempFileRecordRepository.findById(id).orElseGet(TempFileRecord::new); + ValidationUtil.isNull(tempFileRecord.getId(),"TempFileRecord","id",id); + return tempFileRecordMapper.toDto(tempFileRecord); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TempFileRecordDto create(TempFileRecord resources) { + return tempFileRecordMapper.toDto(tempFileRecordRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TempFileRecord resources) { + TempFileRecord tempFileRecord = tempFileRecordRepository.findById(resources.getId()).orElseGet(TempFileRecord::new); + ValidationUtil.isNull( tempFileRecord.getId(),"TempFileRecord","id",resources.getId()); + tempFileRecord.copy(resources); + tempFileRecordRepository.save(tempFileRecord); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + tempFileRecordRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TempFileRecordDto tempFileRecord : all) { + Map map = new LinkedHashMap<>(); + map.put("访问接口的ip地址记录", tempFileRecord.getIpAddrs()); + map.put("文件生成地址", tempFileRecord.getFilePaths()); + map.put("访问文件验证码", tempFileRecord.getVerificationCode()); + map.put("有效保存时间", tempFileRecord.getDays()); + map.put("文件保存状态", tempFileRecord.getFileStatus()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } + + @Override + public TempFileRecord findByVerificationCode(String verificationCode, Integer fileStatus) { + return tempFileRecordRepository.findByVerificationCodeAndFileStatus(verificationCode, fileStatus); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/mapstruct/TempFileRecordMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/mapstruct/TempFileRecordMapper.java new file mode 100644 index 0000000..07c4adf --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/tmpfilerecord/service/mapstruct/TempFileRecordMapper.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.tmpfilerecord.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.tmpfilerecord.domain.TempFileRecord; +import me.zhengjie.modules.tmpfilerecord.service.dto.TempFileRecordDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://el-admin.vip +* @author X +* @date 2020-10-15 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TempFileRecordMapper extends BaseMapper { + +} \ No newline at end of file