重新上传代码
parent
c5df3dd268
commit
38b7eb8a37
@ -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));
|
||||
}
|
||||
}
|
@ -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<Edu, Long>, JpaSpecificationExecutor<Edu> {
|
||||
|
||||
/**
|
||||
* 根据坐标进行查询
|
||||
*
|
||||
* @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<String> findAllMatchDataByPage(@Param("cityCode") List<Integer> cityCode,
|
||||
@Param("stuGrade") List<Integer> 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<Integer> cityCode, List<Integer> stuGrade, Double minX, Double maxX, Double minY, Double maxY);
|
||||
}
|
@ -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<Object> 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<Object> 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<Object> 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<Object> delete(@RequestBody Long[] ids) {
|
||||
eduService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -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<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(EduQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<EduDto>
|
||||
*/
|
||||
List<EduDto> 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<EduDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* 两表条件关联查出需要的发送uid,然后保存在发送表中
|
||||
*
|
||||
* @param cityCode
|
||||
* @param stuGrade
|
||||
* @param rectangle
|
||||
*/
|
||||
Slice<String> queryMatchData(List<Integer> cityCode, List<Integer> stuGrade, Rectangle rectangle, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 计算总数
|
||||
*
|
||||
* @param cities
|
||||
* @param grades
|
||||
* @param rectangle
|
||||
* @return
|
||||
*/
|
||||
long countMatchData(List<Integer> cities, List<Integer> grades, Rectangle rectangle);
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<String,Object> queryAll(EduQueryCriteria criteria, Pageable pageable){
|
||||
Page<Edu> page = eduRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(eduMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EduDto> 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<EduDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (EduDto edu : all) {
|
||||
Map<String,Object> 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<String> queryMatchData(List<Integer> cityCode, List<Integer> 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<String> 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<Integer> cityCode, List<Integer> 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);
|
||||
}
|
||||
}
|
@ -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<EduDto, Edu> {
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
@ -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<School, Long>, JpaSpecificationExecutor<School> {
|
||||
}
|
@ -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<Object> 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<Object> 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<Object> 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<Object> delete(@RequestBody Long[] ids) {
|
||||
schoolService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -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<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(SchoolQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<SchoolDto>
|
||||
*/
|
||||
List<SchoolDto> 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<SchoolDto> all, HttpServletResponse response) throws IOException;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<String,Object> queryAll(SchoolQueryCriteria criteria, Pageable pageable){
|
||||
Page<School> page = schoolRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(schoolMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SchoolDto> 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<SchoolDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (SchoolDto school : all) {
|
||||
Map<String,Object> 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);
|
||||
}
|
||||
}
|
@ -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<SchoolDto, School> {
|
||||
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
@ -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<Tag, Long>, JpaSpecificationExecutor<Tag> {
|
||||
}
|
@ -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<Object> 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<Object> 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<Object> 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<Object> delete(@RequestBody Long[] ids) {
|
||||
tagService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -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<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(TagQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
|
||||
/**
|
||||
* 查询数据分页
|
||||
* @param criteria 条件
|
||||
* @param pageable 分页参数
|
||||
* @return Map<String,Object>
|
||||
*/
|
||||
List<Tag> queryAllBySlice(TagQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<TagDto>
|
||||
*/
|
||||
List<TagDto> 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<TagDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*
|
||||
* @param collect
|
||||
* @return
|
||||
*/
|
||||
Integer saveAll(List<Tag> collect);
|
||||
|
||||
/**
|
||||
* 批量更新分表状态
|
||||
*
|
||||
* @param pushIds
|
||||
* @param taskId
|
||||
* @return
|
||||
*/
|
||||
Integer updateAllPushStatus(List<Long> pushIds, Long taskId);
|
||||
|
||||
/**
|
||||
* 按条件进行查询并批量插入
|
||||
*
|
||||
* @param cityCode
|
||||
* @param stuGrade
|
||||
* @param rectangle
|
||||
*/
|
||||
Integer queryAndBatchInsertData(Integer taskId,List<Integer> cityCode, List<Integer> stuGrade, Rectangle rectangle);
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<String,Object> queryAll(TagQueryCriteria criteria, Pageable pageable){
|
||||
Page<Tag> page = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(tagMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Tag> queryAllBySlice(TagQueryCriteria criteria, Pageable pageable) {
|
||||
Slice<Tag> slice = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return slice.getContent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TagDto> 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<TagDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (TagDto tag : all) {
|
||||
Map<String,Object> 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<Tag> collect) {
|
||||
if (CollectionUtils.isEmpty(collect)){
|
||||
return 0;
|
||||
}
|
||||
List<Tag> 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<Integer> cityCode, List<Integer> 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<Long> 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();
|
||||
}
|
||||
}
|
@ -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<TagDto, Tag> {
|
||||
|
||||
}
|
@ -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<TempFileRecord, Integer>, JpaSpecificationExecutor<TempFileRecord> {
|
||||
|
||||
TempFileRecord findByVerificationCodeAndFileStatus(String verificationCode, Integer fileStatus);
|
||||
}
|
@ -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<Object> 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<Object> 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<Object> 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<Object> delete(@RequestBody Integer[] ids) {
|
||||
tempFileRecordService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
}
|
@ -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<String,Object>
|
||||
*/
|
||||
Map<String,Object> queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable);
|
||||
|
||||
/**
|
||||
* 查询所有数据不分页
|
||||
* @param criteria 条件参数
|
||||
* @return List<TempFileRecordDto>
|
||||
*/
|
||||
List<TempFileRecordDto> 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<TempFileRecordDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
|
||||
/**
|
||||
* 根据文件访问验证码进行访问
|
||||
*/
|
||||
TempFileRecord findByVerificationCode(String verificationCode, Integer fileStatus);
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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<String,Object> queryAll(TempFileRecordQueryCriteria criteria, Pageable pageable){
|
||||
Page<TempFileRecord> page = tempFileRecordRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
||||
return PageUtil.toPage(page.map(tempFileRecordMapper::toDto));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TempFileRecordDto> 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<TempFileRecordDto> all, HttpServletResponse response) throws IOException {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
for (TempFileRecordDto tempFileRecord : all) {
|
||||
Map<String,Object> 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);
|
||||
}
|
||||
}
|
@ -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<TempFileRecordDto, TempFileRecord> {
|
||||
|
||||
}
|
Loading…
Reference in New Issue