|
|
|
@ -3,12 +3,16 @@ package com.logpm.report.service.impl;
|
|
|
|
|
import com.logpm.report.mapper.StockOutDetailMapper; |
|
|
|
|
import com.logpm.report.service.StockOutDetailService; |
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
|
|
import org.apache.ibatis.cursor.Cursor; |
|
|
|
|
import org.apache.ibatis.session.SqlSession; |
|
|
|
|
import org.apache.ibatis.session.SqlSessionFactory; |
|
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
import org.springblade.core.redis.cache.BladeRedis; |
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
|
|
import java.util.Collection; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 库存品出口明细报表 |
|
|
|
@ -19,6 +23,10 @@ public class StockOutDetailServiceImp implements StockOutDetailService {
|
|
|
|
|
|
|
|
|
|
private StockOutDetailMapper testMapper; |
|
|
|
|
|
|
|
|
|
private BladeRedis redis; |
|
|
|
|
|
|
|
|
|
private SqlSessionFactory sqlSessionFactory; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 报表统计信息 |
|
|
|
|
* |
|
|
|
@ -28,8 +36,66 @@ public class StockOutDetailServiceImp implements StockOutDetailService {
|
|
|
|
|
* @return 查询结果 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public List<Map<String, Object>> report(Integer current, Integer size, Map<String, Object> query) { |
|
|
|
|
public Map<String, Object> report(Integer current, Integer size, Map<String, Object> query) { |
|
|
|
|
|
|
|
|
|
HashMap<String, Object> res = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
res.put("records", getList(current, size, query)); |
|
|
|
|
res.put("total", getCount(query)); |
|
|
|
|
res.put("current", current); |
|
|
|
|
res.put("size", size); |
|
|
|
|
res.put("pages", (int) Math.ceil((double) (int) res.get("total") / size)); |
|
|
|
|
|
|
|
|
|
return res; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 报表导出 |
|
|
|
|
* |
|
|
|
|
* @param where 条件 |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void reportExport(Map<String, Object> where) { |
|
|
|
|
try ( |
|
|
|
|
SqlSession sqlSession = sqlSessionFactory.openSession(); |
|
|
|
|
Cursor<Map<String, Object>> listCursor = sqlSession.getMapper(StockOutDetailMapper.class).getListCursor(where) |
|
|
|
|
) { |
|
|
|
|
|
|
|
|
|
listCursor.forEach(stringObjectMap -> { |
|
|
|
|
// 写入 excel
|
|
|
|
|
System.out.println(stringObjectMap.get("id")); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当前查询的数据 |
|
|
|
|
* |
|
|
|
|
* @param current 当前页数 |
|
|
|
|
* @param size 数据量 |
|
|
|
|
* @param query 查询条件集合 |
|
|
|
|
* @return 数据列表 |
|
|
|
|
*/ |
|
|
|
|
private List<Map<String, Object>> getList(Integer current, Integer size, Map<String, Object> query) { |
|
|
|
|
Integer offset = (current - 1) * size; |
|
|
|
|
query.put("offset", offset); |
|
|
|
|
query.put("size", size); |
|
|
|
|
|
|
|
|
|
return testMapper.getList(query); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 获取当前查询的总数据量 |
|
|
|
|
* |
|
|
|
|
* @param query 请求的参数集合 |
|
|
|
|
* @return 数量 |
|
|
|
|
*/ |
|
|
|
|
@Nullable |
|
|
|
|
private Integer getCount(Map<String, Object> query) { |
|
|
|
|
// 是否需要获取缓存的数据,如果没有查询条件时才获取缓存数据
|
|
|
|
|
boolean getCacheCount = true; |
|
|
|
|
long whereCount = query.entrySet().stream().filter((entry) -> entry.getValue() != null) |
|
|
|
|
.filter(entry -> !entry.getKey().equals("current") && !entry.getKey().equals("size")) |
|
|
|
@ -38,12 +104,18 @@ public class StockOutDetailServiceImp implements StockOutDetailService {
|
|
|
|
|
getCacheCount = false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
query.put("offset", offset); |
|
|
|
|
query.put("size", size); |
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> List = testMapper.getList(query); |
|
|
|
|
Integer count = testMapper.getCount(query); |
|
|
|
|
Integer count; |
|
|
|
|
if (getCacheCount) { |
|
|
|
|
// 这里的key需要调整为租户模式
|
|
|
|
|
String key = "test-st"; |
|
|
|
|
if (!redis.exists(key)) { |
|
|
|
|
redis.setEx(key, testMapper.getCount(query), 600L); |
|
|
|
|
} |
|
|
|
|
count = redis.get(key); |
|
|
|
|
} else { |
|
|
|
|
count = testMapper.getCount(query); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return List; |
|
|
|
|
return count; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|