|
|
@ -1,18 +1,18 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2019-2020 Zheng Jie
|
|
|
|
* Copyright 2019-2020 Zheng Jie
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package me.zhengjie.modules.tag.service.impl;
|
|
|
|
package me.zhengjie.modules.tag.service.impl;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
@ -49,15 +49,15 @@ import javax.persistence.PersistenceContext;
|
|
|
|
import javax.persistence.Query;
|
|
|
|
import javax.persistence.Query;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.math.BigInteger;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @website https://el-admin.vip
|
|
|
|
* @author x
|
|
|
|
* @description 服务实现
|
|
|
|
* @website https://el-admin.vip
|
|
|
|
* @author x
|
|
|
|
* @description 服务实现
|
|
|
|
* @date 2020-09-22
|
|
|
|
* @date 2020-09-22
|
|
|
|
**/
|
|
|
|
**/
|
|
|
|
@Slf4j
|
|
|
|
@Slf4j
|
|
|
|
@Service
|
|
|
|
@Service
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
@ -74,27 +74,27 @@ public class TagServiceImpl implements TagService {
|
|
|
|
private EntityManager entityManager;
|
|
|
|
private EntityManager entityManager;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Map<String,Object> queryAll(TagQueryCriteria criteria, Pageable pageable){
|
|
|
|
public Map<String, Object> queryAll(TagQueryCriteria criteria, Pageable pageable) {
|
|
|
|
Page<Tag> page = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
|
|
|
Page<Tag> page = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
|
|
|
return PageUtil.toPage(page.map(tagMapper::toDto));
|
|
|
|
return PageUtil.toPage(page.map(tagMapper::toDto));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Tag> queryAllBySlice(TagQueryCriteria criteria, Pageable pageable) {
|
|
|
|
public List<Tag> queryAllBySlice(TagQueryCriteria criteria, Pageable pageable) {
|
|
|
|
Slice<Tag> slice = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
|
|
|
|
Slice<Tag> slice = tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
|
|
|
|
return slice.getContent();
|
|
|
|
return slice.getContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<TagDto> queryAll(TagQueryCriteria criteria){
|
|
|
|
public List<TagDto> queryAll(TagQueryCriteria criteria) {
|
|
|
|
return tagMapper.toDto(tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
|
|
|
|
return tagMapper.toDto(tagRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional
|
|
|
|
@Transactional
|
|
|
|
public TagDto findById(Long id) {
|
|
|
|
public TagDto findById(Long id) {
|
|
|
|
Tag tag = tagRepository.findById(id).orElseGet(Tag::new);
|
|
|
|
Tag tag = tagRepository.findById(id).orElseGet(Tag::new);
|
|
|
|
ValidationUtil.isNull(tag.getId(),"Tag","id",id);
|
|
|
|
ValidationUtil.isNull(tag.getId(), "Tag", "id", id);
|
|
|
|
return tagMapper.toDto(tag);
|
|
|
|
return tagMapper.toDto(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -108,7 +108,7 @@ public class TagServiceImpl implements TagService {
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public void update(Tag resources) {
|
|
|
|
public void update(Tag resources) {
|
|
|
|
Tag tag = tagRepository.findById(resources.getId()).orElseGet(Tag::new);
|
|
|
|
Tag tag = tagRepository.findById(resources.getId()).orElseGet(Tag::new);
|
|
|
|
ValidationUtil.isNull( tag.getId(),"Tag","id",resources.getId());
|
|
|
|
ValidationUtil.isNull(tag.getId(), "Tag", "id", resources.getId());
|
|
|
|
tag.copy(resources);
|
|
|
|
tag.copy(resources);
|
|
|
|
tagRepository.save(tag);
|
|
|
|
tagRepository.save(tag);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -124,10 +124,10 @@ public class TagServiceImpl implements TagService {
|
|
|
|
public void download(List<TagDto> all, HttpServletResponse response) throws IOException {
|
|
|
|
public void download(List<TagDto> all, HttpServletResponse response) throws IOException {
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
for (TagDto tag : all) {
|
|
|
|
for (TagDto tag : all) {
|
|
|
|
Map<String,Object> map = new LinkedHashMap<>();
|
|
|
|
Map<String, Object> map = new LinkedHashMap<>();
|
|
|
|
map.put(" uid", tag.getUid());
|
|
|
|
map.put(" uid", tag.getUid());
|
|
|
|
map.put(" taskId", tag.getTaskId());
|
|
|
|
map.put(" taskId", tag.getTaskId());
|
|
|
|
map.put(" pushStatus", tag.getPushStatus());
|
|
|
|
map.put(" pushStatus", tag.getPushStatus());
|
|
|
|
list.add(map);
|
|
|
|
list.add(map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FileUtil.downloadExcel(list, response);
|
|
|
|
FileUtil.downloadExcel(list, response);
|
|
|
@ -136,11 +136,11 @@ public class TagServiceImpl implements TagService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public Integer saveAll(List<Tag> collect) {
|
|
|
|
public Integer saveAll(List<Tag> collect) {
|
|
|
|
if (CollectionUtils.isEmpty(collect)){
|
|
|
|
if (CollectionUtils.isEmpty(collect)) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Tag> tagList= tagRepository.saveAll(collect);
|
|
|
|
List<Tag> tagList = tagRepository.saveAll(collect);
|
|
|
|
if (CollectionUtils.isEmpty(tagList)){
|
|
|
|
if (CollectionUtils.isEmpty(tagList)) {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tagList.size();
|
|
|
|
return tagList.size();
|
|
|
@ -176,7 +176,7 @@ public class TagServiceImpl implements TagService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 坐标
|
|
|
|
// 坐标
|
|
|
|
if (Objects.nonNull(rectangle)){
|
|
|
|
if (Objects.nonNull(rectangle)) {
|
|
|
|
whereSql.append(" AND s.lng >= :minX AND s.lng < :maxX AND s.lat >= :minY AND s.lat < :maxY ");
|
|
|
|
whereSql.append(" AND s.lng >= :minX AND s.lng < :maxX AND s.lat >= :minY AND s.lat < :maxY ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 拼接成完整sql
|
|
|
|
// 拼接成完整sql
|
|
|
@ -186,13 +186,13 @@ public class TagServiceImpl implements TagService {
|
|
|
|
//创建本地sql查询实例
|
|
|
|
//创建本地sql查询实例
|
|
|
|
Query dataQuery = entityManager.createNativeQuery(insertSql.toString());
|
|
|
|
Query dataQuery = entityManager.createNativeQuery(insertSql.toString());
|
|
|
|
// 设置参数
|
|
|
|
// 设置参数
|
|
|
|
if (CollectionUtil.isNotEmpty(stuGrade)){
|
|
|
|
if (CollectionUtil.isNotEmpty(stuGrade)) {
|
|
|
|
dataQuery.setParameter("stuGrade", stuGrade);
|
|
|
|
dataQuery.setParameter("stuGrade", stuGrade);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (CollectionUtil.isNotEmpty(cityCode)){
|
|
|
|
if (CollectionUtil.isNotEmpty(cityCode)) {
|
|
|
|
dataQuery.setParameter("cityCode", cityCode);
|
|
|
|
dataQuery.setParameter("cityCode", cityCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Objects.nonNull(rectangle)){
|
|
|
|
if (Objects.nonNull(rectangle)) {
|
|
|
|
// 经度范围
|
|
|
|
// 经度范围
|
|
|
|
dataQuery.setParameter("minX", rectangle.getMinX());
|
|
|
|
dataQuery.setParameter("minX", rectangle.getMinX());
|
|
|
|
dataQuery.setParameter("maxX", rectangle.getMaxX());
|
|
|
|
dataQuery.setParameter("maxX", rectangle.getMaxX());
|
|
|
@ -290,26 +290,50 @@ public class TagServiceImpl implements TagService {
|
|
|
|
return Boolean.FALSE;
|
|
|
|
return Boolean.FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
public boolean deleteByTaskId(Integer id) {
|
|
|
|
public boolean deleteByTaskId(Integer id) {
|
|
|
|
// 获取分表下标
|
|
|
|
// 获取分表下标
|
|
|
|
int resultId = id % tableSum;
|
|
|
|
int resultId = id % tableSum;
|
|
|
|
String deleteStr = "DELETE FROM dc_tag"
|
|
|
|
String deleteStr = "DELETE FROM dc_tag"
|
|
|
|
+ resultId
|
|
|
|
+ resultId
|
|
|
|
+ " WHERE task_id = :id";
|
|
|
|
+ " WHERE task_id = :id ";
|
|
|
|
Query deleteQuery = entityManager.createNativeQuery(deleteStr);
|
|
|
|
Query deleteQuery = entityManager.createNativeQuery(deleteStr);
|
|
|
|
deleteQuery.setParameter("id", id);
|
|
|
|
deleteQuery.setParameter("id", id);
|
|
|
|
// 执行删除任务
|
|
|
|
// 执行删除任务
|
|
|
|
boolean result = deleteQuery.executeUpdate() > 0;
|
|
|
|
boolean result = deleteQuery.executeUpdate() > 0;
|
|
|
|
if (result){
|
|
|
|
if (result) {
|
|
|
|
|
|
|
|
//数据中需要删除的数据量
|
|
|
|
|
|
|
|
long expiredCount;
|
|
|
|
|
|
|
|
//已经删除数据量
|
|
|
|
|
|
|
|
long totalDeleted = 0L;
|
|
|
|
// 删除之前记录 分表情况下,单次可能会有遗漏 多次并不影响
|
|
|
|
// 删除之前记录 分表情况下,单次可能会有遗漏 多次并不影响
|
|
|
|
String replaceStr = StringUtils.replace(deleteStr, " = ", " < ");
|
|
|
|
String replaceStr = StringUtils.replace(deleteStr, " = ", " < ");
|
|
|
|
Query deleteTagByQuery = entityManager.createNativeQuery(replaceStr);
|
|
|
|
do {
|
|
|
|
deleteTagByQuery.setParameter("id", id);
|
|
|
|
Query deleteTagByQuery = entityManager.createNativeQuery(replaceStr + " limit 50000");
|
|
|
|
deleteTagByQuery.executeUpdate();
|
|
|
|
deleteTagByQuery.setParameter("id", id);
|
|
|
|
|
|
|
|
int executeUpdate = deleteTagByQuery.executeUpdate();
|
|
|
|
|
|
|
|
totalDeleted += executeUpdate;
|
|
|
|
|
|
|
|
expiredCount = queryCount(resultId, id);
|
|
|
|
|
|
|
|
} while (expiredCount > 0);
|
|
|
|
|
|
|
|
log.info("======== delete tag{} table size as [{}] ========", resultId, totalDeleted);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 查询数据
|
|
|
|
|
|
|
|
* @param resultId
|
|
|
|
|
|
|
|
* @param id
|
|
|
|
|
|
|
|
* @return
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private Long queryCount(int resultId, int id) {
|
|
|
|
|
|
|
|
String sql = "select count(1) FROM dc_tag" + resultId + " where task_id < :id ";
|
|
|
|
|
|
|
|
Query selectQueryCount = entityManager.createNativeQuery(sql);
|
|
|
|
|
|
|
|
selectQueryCount.setParameter("id", id);
|
|
|
|
|
|
|
|
BigInteger bigInteger = (BigInteger) selectQueryCount.getSingleResult();
|
|
|
|
|
|
|
|
return bigInteger.longValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|