mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
Merge remote-tracking branch 'origin/main'
This commit is contained in:
+99
@@ -0,0 +1,99 @@
|
||||
package com.cf.imes.framework.common.util.encrypt;
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.KeyGenerator;
|
||||
import javax.crypto.SecretKey;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Base64;
|
||||
|
||||
/**
|
||||
* AES对称加密工具
|
||||
*
|
||||
* @author Gqr
|
||||
* @since 2024/8/23 16:38
|
||||
*/
|
||||
@Slf4j
|
||||
public class AesUtils {
|
||||
|
||||
private static final String AES_ALG = "AES";
|
||||
|
||||
private static final String AES_CBC_PCK_ALG = "AES/CBC/PKCS5Padding";
|
||||
|
||||
|
||||
/**
|
||||
* 解密
|
||||
*
|
||||
* @param content
|
||||
* @param aesKey
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static String decrypt(String content, String aesKey) {
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(AES_CBC_PCK_ALG);
|
||||
IvParameterSpec iv = new IvParameterSpec(initIv(AES_CBC_PCK_ALG));
|
||||
cipher.init(Cipher.DECRYPT_MODE, generateKey(aesKey.getBytes()), iv);
|
||||
|
||||
byte[] cleanBytes = cipher.doFinal(Base64.getDecoder().decode(content.getBytes()));
|
||||
return new String(cleanBytes, CharsetUtil.UTF_8);
|
||||
} catch (Exception e) {
|
||||
log.error("[AesUtils][decrypt]解密失败:{}", e.getMessage(), e);
|
||||
// nacos热发布配置,空字符串会导致nacos轮训刷新配置
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成key
|
||||
*
|
||||
* @param bytes
|
||||
* @return
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
private static SecretKey generateKey(byte[] bytes) throws NoSuchAlgorithmException {
|
||||
// 生成随机数
|
||||
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
|
||||
// 设置随机数种子
|
||||
random.setSeed(bytes);
|
||||
|
||||
// aes算法生成器
|
||||
KeyGenerator keyGen = KeyGenerator.getInstance(AES_ALG);
|
||||
keyGen.init(128, random); // 使用128位的密钥
|
||||
return keyGen.generateKey();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始向量的方法, 全部为0. 这里的写法适合于其它算法,针对AES算法的话,IV值一定是128位的(16字节).
|
||||
*
|
||||
* @param fullAlg
|
||||
* @return
|
||||
* @throws GeneralSecurityException
|
||||
*/
|
||||
private static byte[] initIv(String fullAlg) {
|
||||
|
||||
try {
|
||||
Cipher cipher = Cipher.getInstance(fullAlg);
|
||||
int blockSize = cipher.getBlockSize();
|
||||
byte[] iv = new byte[blockSize];
|
||||
for (int i = 0; i < blockSize; ++i) {
|
||||
iv[i] = 0;
|
||||
}
|
||||
return iv;
|
||||
} catch (Exception e) {
|
||||
|
||||
int blockSize = 16;
|
||||
byte[] iv = new byte[blockSize];
|
||||
for (int i = 0; i < blockSize; ++i) {
|
||||
iv[i] = 0;
|
||||
}
|
||||
return iv;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -20,10 +20,11 @@ public class CompressStringTypeHandler extends StringTypeHandler {
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType)
|
||||
throws SQLException {
|
||||
String compressString = null;
|
||||
if (StringUtils.isNotEmpty(parameter)) {
|
||||
String compressString = JsonUtils.zipString(parameter);
|
||||
ps.setString(i, compressString);
|
||||
compressString = JsonUtils.zipString(parameter);
|
||||
}
|
||||
ps.setString(i, compressString);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-7
@@ -1,6 +1,5 @@
|
||||
package com.cf.imes.framework.security.core.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.exception.enums.GlobalErrorCodeConstants;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
@@ -44,7 +43,7 @@ public class SecurityFrameworkUtils {
|
||||
String headerName, String parameterName) {
|
||||
// 1. 获得 Token。优先级:Header > Parameter
|
||||
String token = request.getHeader(headerName);
|
||||
if (StrUtil.isEmpty(token)) {
|
||||
if (StringUtils.isEmpty(token)) {
|
||||
token = request.getParameter(parameterName);
|
||||
}
|
||||
if (!StringUtils.hasText(token)) {
|
||||
@@ -63,7 +62,7 @@ public class SecurityFrameworkUtils {
|
||||
public static Authentication getAuthentication() {
|
||||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
if (context == null) {
|
||||
return null;
|
||||
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
|
||||
}
|
||||
return context.getAuthentication();
|
||||
}
|
||||
@@ -90,10 +89,7 @@ public class SecurityFrameworkUtils {
|
||||
@Nullable
|
||||
public static Long getLoginUserId() {
|
||||
LoginUser loginUser = getLoginUser();
|
||||
if (loginUser == null) {
|
||||
throw new ServiceException(GlobalErrorCodeConstants.UNAUTHORIZED);
|
||||
}
|
||||
return loginUser.getId();
|
||||
return loginUser != null ? loginUser.getId() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -90,7 +90,7 @@ public class OrderStatisticsController {
|
||||
@GetMapping("/bigPlateCount/group")
|
||||
@Operation(summary = "大板数量分组统计")
|
||||
public CommonResult<Map<String, Object>> getBigPlateCount(@Valid OrderStatisticsReqVO reqVO) {
|
||||
return success(null);
|
||||
return success(orderStatisticsService.getBigPlateCountGroup(reqVO));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-5
@@ -6,13 +6,12 @@ import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisti
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
|
||||
import com.cf.imes.module.executor.enums.OrderDeletedEnum;
|
||||
import com.cf.imes.module.executor.enums.OrderStatusEnum;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -27,7 +26,7 @@ public interface OrderStatisticsMapper extends BaseMapperX<OrderDO> {
|
||||
*/
|
||||
default Integer selectOrderCount() {
|
||||
return Math.toIntExact(selectCount(new LambdaQueryWrapperX<OrderDO>()
|
||||
.eq(OrderDO::getDeleted, 0)));
|
||||
.eq(OrderDO::getDeleted, OrderDeletedEnum.NOT_DELETED.getStatus())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,6 +35,7 @@ public interface OrderStatisticsMapper extends BaseMapperX<OrderDO> {
|
||||
*/
|
||||
default Integer selectOrderCountToday() {
|
||||
return Math.toIntExact(selectCount(new LambdaQueryWrapperX<OrderDO>()
|
||||
.eq(OrderDO::getDeleted, OrderDeletedEnum.NOT_DELETED.getStatus())
|
||||
.eq(OrderDO::getOrderDate, LocalDate.now())));
|
||||
|
||||
}
|
||||
@@ -46,7 +46,9 @@ public interface OrderStatisticsMapper extends BaseMapperX<OrderDO> {
|
||||
*/
|
||||
default Integer selectOrderCountTodayFinish() {
|
||||
return Math.toIntExact(selectCount(new LambdaQueryWrapperX<OrderDO>()
|
||||
.between(OrderDO::getFinishTime, LocalDateTime.of(LocalDate.now(), LocalTime.MIN), LocalDateTime.of(LocalDate.now(), LocalTime.MAX))));
|
||||
.eq(OrderDO::getDeleted, OrderDeletedEnum.NOT_DELETED.getStatus())
|
||||
.eq(OrderDO::getStatus, OrderStatusEnum.FINISH_PRODUCTION.getStatus())
|
||||
.eq(OrderDO::getFinishTime, LocalDate.now())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,13 +57,14 @@ public interface OrderStatisticsMapper extends BaseMapperX<OrderDO> {
|
||||
*/
|
||||
default Integer selectOrderCountProduce() {
|
||||
return Math.toIntExact(selectCount(new LambdaQueryWrapperX<OrderDO>()
|
||||
.eq(OrderDO::getDeleted, OrderDeletedEnum.NOT_DELETED.getStatus())
|
||||
.eq(OrderDO::getStatus, OrderStatusEnum.IN_PRODUCTION.getStatus())));
|
||||
}
|
||||
|
||||
/**
|
||||
* 生产中生产平方数
|
||||
*
|
||||
* @param organId
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
Integer selectOrderSquareProduce();
|
||||
|
||||
+8
@@ -72,4 +72,12 @@ public interface OrderStatisticsService {
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getOrderPlateAreaGroup(OrderStatisticsReqVO reqVO);
|
||||
|
||||
/**
|
||||
* 大板数量分组统计
|
||||
*
|
||||
* @param reqVO
|
||||
* @return
|
||||
*/
|
||||
Map<String, Object> getBigPlateCountGroup(OrderStatisticsReqVO reqVO);
|
||||
}
|
||||
|
||||
+201
-21
@@ -1,24 +1,41 @@
|
||||
package com.cf.imes.module.executor.service.order;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import co.elastic.clients.elasticsearch.ElasticsearchClient;
|
||||
import co.elastic.clients.elasticsearch._types.FieldValue;
|
||||
import co.elastic.clients.elasticsearch._types.SortOrder;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.Aggregate;
|
||||
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.CalendarInterval;
|
||||
import co.elastic.clients.elasticsearch._types.aggregations.DateHistogramAggregation;
|
||||
import co.elastic.clients.elasticsearch.core.SearchRequest;
|
||||
import co.elastic.clients.elasticsearch.core.SearchResponse;
|
||||
import co.elastic.clients.json.JsonData;
|
||||
import co.elastic.clients.util.NamedValue;
|
||||
import com.cf.imes.framework.common.enums.OrderStatusEnum;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderGoodsPlateRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsAreaRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsReqVO;
|
||||
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderStatisticsStatusRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsAreaRespVO;
|
||||
import com.cf.imes.module.executor.controller.admin.plan.vo.OrderPlanStatisticsCountRespVO;
|
||||
import com.cf.imes.module.executor.dal.dataobject.plate.PlateGoodDO;
|
||||
import com.cf.imes.module.executor.dal.mysql.order.OrderStatisticsMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.plan.PlanMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.plate.OrderPlateStatisticsMapper;
|
||||
import com.cf.imes.module.executor.dal.mysql.plate.PlateGoodMapper;
|
||||
import com.cf.imes.module.executor.enums.OrderStatisticsUnit;
|
||||
import com.cf.imes.module.executor.service.optimizeplan.OptimizePlanService;
|
||||
import com.cf.imes.module.system.api.dict.DictDataApi;
|
||||
import com.cf.imes.module.system.api.dict.dto.DictDataRespDTO;
|
||||
import com.cf.imes.module.system.enums.DictTypeConstants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@@ -40,6 +57,7 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
@Resource
|
||||
private OrderStatisticsMapper orderStatisticsMapper;
|
||||
@@ -53,9 +71,20 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
@Resource
|
||||
private DictDataApi dictDataApi;
|
||||
|
||||
@Resource
|
||||
private PlateGoodMapper plateGoodMapper;
|
||||
|
||||
@Resource
|
||||
private ElasticsearchClient client;
|
||||
|
||||
// 常用的字段key
|
||||
private static final String DATELIST_FIELD_NAME = "dateList";
|
||||
private static final String SERIES_FIELD_NAME = "series";
|
||||
private static final String ORDER_REMAIN_PLATE_MODEL_CREATE_TIME_FIELDNAME = "createTime";
|
||||
private static final String ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME = "goods_group";
|
||||
private static final String ORDER_REMAIN_PLATE_MODEL_GOODS_COUNT_NAME = "goods_count";
|
||||
private static final String DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH = "yyyy-M";
|
||||
private static final String DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY = "yyyy-M-d";
|
||||
|
||||
@Override
|
||||
public Integer orderCount() {
|
||||
@@ -206,13 +235,10 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
// 所有的日期集合
|
||||
List<String> dateList = getDateList(reqVO);
|
||||
|
||||
// 查询时间段内数量最多的小板,排序列出数量前10的goods_id
|
||||
// 查询时间段内数量最多的小板,列出数量前10的goods_id
|
||||
List<Long> topTenCountGoodsId = orderPlateStatisticsMapper.selectPlateCountList(reqVO).stream()
|
||||
.sorted(Comparator.comparingLong(OrderGoodsPlateRespVO::getOrderCount).reversed())
|
||||
.map(OrderGoodsPlateRespVO::getGoodsId)
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
.toList();
|
||||
|
||||
// 前十goods_id基于时间分组
|
||||
Map<String, List<OrderGoodsPlateRespVO>> orderGoodsPlateRespMap = orderPlateStatisticsMapper.selectTopTenPlateCountListGroupByOrderDate(topTenCountGoodsId, reqVO).stream()
|
||||
@@ -225,7 +251,7 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
List<OrderGoodsPlateRespVO> list = orderGoodsPlateRespMap.values().stream()
|
||||
.flatMap(List::stream)
|
||||
.filter(vo -> vo.getGoodsId().equals(id))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
if (!list.isEmpty()) {
|
||||
// goodsId相同,其他属性任取
|
||||
goodsMap.put(id, list.get(0));
|
||||
@@ -277,12 +303,10 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
// 所有的日期集合
|
||||
List<String> dateList = getDateList(reqVO);
|
||||
|
||||
// 查询时间段内面积最多的小板,排序列出前10面积的goods_id
|
||||
// 查询时间段内面积最多的小板,列出前10面积的goods_id
|
||||
List<Long> topTenCountGoodsId = orderPlateStatisticsMapper.selectPlateAreaList(reqVO).stream()
|
||||
.sorted(Comparator.comparing(OrderGoodsPlateRespVO::getOrderArea).reversed())
|
||||
.map(OrderGoodsPlateRespVO::getGoodsId)
|
||||
.limit(10)
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
|
||||
|
||||
// 前十goods_id基于时间分组
|
||||
@@ -296,7 +320,7 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
List<OrderGoodsPlateRespVO> list = orderGoodsPlateRespMap.values().stream()
|
||||
.flatMap(List::stream)
|
||||
.filter(vo -> vo.getGoodsId().equals(id))
|
||||
.collect(Collectors.toList());
|
||||
.toList();
|
||||
if (!list.isEmpty()) {
|
||||
// goodsId相同,其他属性任取
|
||||
goodsMap.put(id, list.get(0));
|
||||
@@ -341,6 +365,167 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getBigPlateCountGroup(OrderStatisticsReqVO reqVO) {
|
||||
Map<String, Object> resultMap = new LinkedHashMap<>();
|
||||
Integer unit = reqVO.getUnit();
|
||||
|
||||
// 所有的日期集合
|
||||
List<String> dateList = getDateList(reqVO);
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
|
||||
SearchResponse<Map> response;
|
||||
try {
|
||||
// 查询创建时间段内,数量最多的goods_id前十
|
||||
SearchRequest searchRequest = new SearchRequest.Builder()
|
||||
.size(0)
|
||||
.index(OptimizePlanService.ORDER_REMAIN_PLATE_MODEL)
|
||||
.query(q -> q.range(r -> r.field(ORDER_REMAIN_PLATE_MODEL_CREATE_TIME_FIELDNAME)
|
||||
.gte(JsonData.of(reqVO.getCreateTime()[0].format(dateTimeFormatter)))
|
||||
.lte(JsonData.of(reqVO.getCreateTime()[1].format(dateTimeFormatter))))
|
||||
)
|
||||
.aggregations(ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME,
|
||||
agg -> agg.terms(terms -> terms.field("id").size(10).order(new NamedValue<>(ORDER_REMAIN_PLATE_MODEL_GOODS_COUNT_NAME, SortOrder.Desc)))
|
||||
.aggregations(ORDER_REMAIN_PLATE_MODEL_GOODS_COUNT_NAME, sumAgg -> sumAgg.sum(sum -> sum.field("boardCount")))
|
||||
)
|
||||
.build();
|
||||
|
||||
response = client.search(searchRequest, Map.class);
|
||||
|
||||
Map<String, Aggregate> goodsCountAggMap = response.aggregations();
|
||||
Aggregate goodsCountAgg = goodsCountAggMap.get(ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME);
|
||||
|
||||
List<FieldValue> goodsIds = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 获取数量最大前十的goodsId列表
|
||||
*/
|
||||
goodsCountAgg.sterms().buckets().array().forEach(e -> goodsIds.add(e.key()));
|
||||
// 查询创建时间段内,数量最多的goods_id前十下的数据,按goods_id和日期分组
|
||||
SearchRequest dateGroupRequest = new SearchRequest.Builder()
|
||||
.size(0)
|
||||
.index(OptimizePlanService.ORDER_REMAIN_PLATE_MODEL)
|
||||
.query(q -> q.range(r -> r.field(ORDER_REMAIN_PLATE_MODEL_CREATE_TIME_FIELDNAME)
|
||||
.gte(JsonData.of(reqVO.getCreateTime()[0].format(dateTimeFormatter)))
|
||||
.lte(JsonData.of(reqVO.getCreateTime()[1].format(dateTimeFormatter))))
|
||||
)
|
||||
.query(q -> q.bool(b -> b.must(m -> m.terms(t -> t.field("goods_id").terms(tv -> tv.value(goodsIds))))))
|
||||
.query(q -> q.match(m -> m.field("organId").query(SecurityFrameworkUtils.getUserOrganId())))
|
||||
.aggregations(ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME,
|
||||
agg -> agg.terms(terms -> terms.field("id").order(new NamedValue<>(ORDER_REMAIN_PLATE_MODEL_GOODS_COUNT_NAME, SortOrder.Desc)))
|
||||
.aggregations("date_group", dateAgg -> dateAgg.dateHistogram(date -> getDateHistogram(unit, date.field(ORDER_REMAIN_PLATE_MODEL_CREATE_TIME_FIELDNAME))))
|
||||
.aggregations(ORDER_REMAIN_PLATE_MODEL_GOODS_COUNT_NAME, sumAgg -> sumAgg.sum(sum -> sum.field("boardCount")))
|
||||
)
|
||||
.build();
|
||||
response = client.search(dateGroupRequest, Map.class);
|
||||
Map<String, Aggregate> goodsDateCountAggMap = response.aggregations();
|
||||
Aggregate goodsDateAgg = goodsDateCountAggMap.get(ORDER_REMAIN_PLATE_MODEL_GOODS_GROUP_NAME);
|
||||
|
||||
// 构建map:{日期:{goodsId、count}}
|
||||
Map<String, List<OrderGoodsPlateRespVO>> goodsDateGroupMap = new HashMap<>();
|
||||
goodsDateAgg.sterms().buckets().array().forEach(goodsDateAggBucket -> {
|
||||
String goodsId = goodsDateAggBucket.key().stringValue();
|
||||
// todo 目前没有发现好的es统计月周的方式,先把年月日查出来转周,后续优化
|
||||
String dateStr = dateToWeekMonth(goodsDateAggBucket.aggregations().get("date_group").dateHistogram().buckets().array().get(0).keyAsString(), unit);
|
||||
double goodsCount = goodsDateAggBucket.aggregations().get(ORDER_REMAIN_PLATE_MODEL_GOODS_COUNT_NAME).sum().value();
|
||||
OrderGoodsPlateRespVO vo = OrderGoodsPlateRespVO.builder().goodsId(Long.parseLong(goodsId)).orderDate(dateStr).orderCount((int) goodsCount).build();
|
||||
List<OrderGoodsPlateRespVO> orderGoodsPlateRespVOS = goodsDateGroupMap.get(dateStr);
|
||||
if (ObjectUtil.isNotNull(orderGoodsPlateRespVOS)) {
|
||||
orderGoodsPlateRespVOS.add(vo);
|
||||
} else {
|
||||
ArrayList<OrderGoodsPlateRespVO> goodsPlateRespVOS = new ArrayList<>();
|
||||
goodsPlateRespVOS.add(vo);
|
||||
goodsDateGroupMap.put(dateStr, goodsPlateRespVOS);
|
||||
}
|
||||
});
|
||||
|
||||
// 遍历所有goods_id
|
||||
List<Map<String, Object>> series = new ArrayList<>();
|
||||
for (FieldValue goodsIdFieldValue : goodsIds) {
|
||||
String goodsIdStr = goodsIdFieldValue.stringValue();
|
||||
Long goodsId = Long.parseLong(goodsIdStr);
|
||||
Map<String, Object> seriesItem = new HashMap<>();
|
||||
int[] countArr = new int[dateList.size()];
|
||||
|
||||
// 遍历完整的日期范围
|
||||
int index = 0;
|
||||
for (String dateStr : dateList) {
|
||||
// 查找匹配的goodsId
|
||||
List<OrderGoodsPlateRespVO> orderGoodsPlateRespVOS = goodsDateGroupMap.get(dateStr);
|
||||
int count = 0;
|
||||
if (orderGoodsPlateRespVOS != null) {
|
||||
count = orderGoodsPlateRespVOS.stream()
|
||||
.filter(respVO -> Objects.equals(goodsId, respVO.getGoodsId()))
|
||||
.map(OrderGoodsPlateRespVO::getOrderCount)
|
||||
.findFirst().orElse(0);
|
||||
}
|
||||
countArr[index++] = count;
|
||||
}
|
||||
|
||||
seriesItem.put("data", countArr);
|
||||
seriesItem.put("id", goodsId);
|
||||
// 材质-商品名称-颜色-纹理-宽-高-厚-品牌
|
||||
PlateGoodDO plateGoodDO = plateGoodMapper.selectById(goodsId);
|
||||
if (ObjectUtil.isNull(plateGoodDO)) {
|
||||
// 没有对应大板不展示
|
||||
log.error("[getBigPlateCountGroup][统计大板数量,查询大板{} 不存在]", goodsId);
|
||||
continue;
|
||||
}
|
||||
// 获取纹路描述
|
||||
DictDataRespDTO grainDTO = dictDataApi.getDictData(DictTypeConstants.GRAIN_TYPE, String.valueOf(plateGoodDO.getTexture())).getData();
|
||||
String texture = ObjectUtil.isNotNull(grainDTO) ? grainDTO.getLabel() : "";
|
||||
seriesItem.put("name", plateGoodDO.getMaterial() + "-" + plateGoodDO.getGoodsName() +
|
||||
"-" + plateGoodDO.getColor() + "-" + texture + "-" + stripTrailingZeros(BigDecimal.valueOf(plateGoodDO.getWidth())) +
|
||||
"×" + stripTrailingZeros(BigDecimal.valueOf(plateGoodDO.getHeight())) + "×" + stripTrailingZeros(BigDecimal.valueOf(plateGoodDO.getThickness())) + "-" + plateGoodDO.getBrand());
|
||||
series.add(seriesItem);
|
||||
}
|
||||
resultMap.put(DATELIST_FIELD_NAME, dateList.stream().map(date -> generateDateRangeAxis(date, unit)).toList());
|
||||
resultMap.put(SERIES_FIELD_NAME, series);
|
||||
} catch (IOException e) {
|
||||
log.error("[getBigPlateCountGroup][统计大板数量异常:{}]", e.getMessage(), e);
|
||||
}
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据统计维度获取es分组的dateHistogram
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private DateHistogramAggregation.Builder getDateHistogram(Integer unit, DateHistogramAggregation.Builder builder) {
|
||||
switch (OrderStatisticsUnit.fromValue(unit)) {
|
||||
case QUARTER:
|
||||
return builder.calendarInterval(CalendarInterval.Quarter).format("yyyy-Q");
|
||||
case MONTH:
|
||||
return builder.calendarInterval(CalendarInterval.Month).format(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH);
|
||||
case DAY, WEEK:
|
||||
default:
|
||||
return builder.calendarInterval(CalendarInterval.Day).format(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 年月日转年月周
|
||||
*
|
||||
* @param dateStr
|
||||
* @return
|
||||
*/
|
||||
private String dateToWeekMonth(String dateStr, Integer unit) {
|
||||
if (OrderStatisticsUnit.WEEK.getValue().equals(unit)) {
|
||||
LocalDate date = LocalDate.parse(dateStr, DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY));
|
||||
// 年月
|
||||
String outDateStr = date.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH));
|
||||
// 计算从月份第一天到当前日期经过了多少周
|
||||
LocalDate monthStart = date.with(TemporalAdjusters.firstDayOfMonth());
|
||||
long weeksInMonth = ChronoUnit.WEEKS.between(monthStart, date) + 1;
|
||||
return outDateStr + "-" + weeksInMonth;
|
||||
}
|
||||
return dateStr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 获取日期区间格式下的所有日期字符串
|
||||
* 1、reqVO设置机构id
|
||||
@@ -372,8 +557,8 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
endTime = now;
|
||||
switch (OrderStatisticsUnit.fromValue(reqVO.getUnit())) {
|
||||
case QUARTER:
|
||||
// 从now往前的2年
|
||||
startTime = now.minusYears(2);
|
||||
// 从now往前的1年
|
||||
startTime = now.minusYears(1);
|
||||
break;
|
||||
case MONTH:
|
||||
// 包含now往前的12个月
|
||||
@@ -419,22 +604,17 @@ public class OrderStatisticsServiceImpl implements OrderStatisticsService {
|
||||
startDate = startDate.plusMonths(3);
|
||||
break;
|
||||
case MONTH:
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M"));
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH));
|
||||
// 加一月
|
||||
startDate = startDate.plusMonths(1);
|
||||
break;
|
||||
case WEEK:
|
||||
// 使用自定义格式表示月份
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M"));
|
||||
// 计算从月份第一天到当前日期经过了多少周
|
||||
LocalDate monthStart = startDate.with(TemporalAdjusters.firstDayOfMonth());
|
||||
long weeksInMonth = ChronoUnit.WEEKS.between(monthStart, startDate) + 1;
|
||||
dateStr = dateStr + "-" + weeksInMonth;
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M-W"));
|
||||
// 加一周
|
||||
startDate = startDate.plusWeeks(1);
|
||||
break;
|
||||
case DAY:
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern("yyyy-M-d"));
|
||||
dateStr = startDate.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMATTER_PATTERN_YEAR_MONTH_DAY));
|
||||
// 加一天
|
||||
startDate = startDate.plusDays(1);
|
||||
break;
|
||||
|
||||
+2
-2
@@ -3,8 +3,8 @@
|
||||
<mapper namespace="com.cf.imes.module.executor.dal.mysql.order.OrderStatisticsMapper">
|
||||
<select id="selectOrderSquareProduce" resultType="java.lang.Integer">
|
||||
SELECT SUM(op.area) as area FROM orders o
|
||||
LEFT JOIN order_plate op on op.order_id = o.id
|
||||
WHERE o.deleted = 0
|
||||
JOIN order_plate op on op.order_id = o.id
|
||||
WHERE o.deleted = 0 and o.status = 3;
|
||||
</select>
|
||||
|
||||
<sql id="dateFormat">
|
||||
|
||||
+5
-7
@@ -140,8 +140,7 @@
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time), '-', DAY(p.create_time)) as date
|
||||
</if>
|
||||
from order_plan p
|
||||
where p.organ_id = #{req.organId}
|
||||
and p.create_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
where p.create_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and p.deleted = 0
|
||||
group by date;
|
||||
</select>
|
||||
@@ -162,11 +161,10 @@
|
||||
,CONCAT(YEAR(p.create_time), '-', MONTH(p.create_time), '-', DAY(p.create_time)) as date
|
||||
</if>
|
||||
from order_plan p
|
||||
join order_plan_item opi on p.id = opi.plan_id and opi.organ_id = #{req.organId}
|
||||
join order_item oi on oi.id = opi.item_id and oi.organ_id = #{req.organId}
|
||||
join order_plate op on oi.plate_id = op.id and op.organ_id = #{req.organId}
|
||||
where p.organ_id = #{req.organId}
|
||||
and p.create_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
join order_plan_item opi on p.id = opi.plan_id
|
||||
join order_item oi on oi.id = opi.item_id
|
||||
join order_plate op on oi.plate_id = op.id
|
||||
where p.create_time between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
and p.deleted = 0
|
||||
group by date;
|
||||
</select>
|
||||
|
||||
+6
-6
@@ -6,12 +6,12 @@
|
||||
count(a.id) as orderCount
|
||||
from order_goods g
|
||||
left join order_plate a ON g.id = a.goods_id and a.deleted = 0
|
||||
left join orders o ON o.id = a.order_id and o.deleted = 0
|
||||
join orders o ON o.id = a.order_id and o.deleted = 0
|
||||
where g.deleted = 0
|
||||
and o.order_date between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
group by g.goods_id
|
||||
having orderCount > 0
|
||||
order by null;
|
||||
order by orderCount desc
|
||||
limit 10;
|
||||
</select>
|
||||
|
||||
<select id="selectTopTenPlateCountListGroupByOrderDate" resultType="com.cf.imes.module.executor.controller.admin.order.vo.order.OrderGoodsPlateRespVO">
|
||||
@@ -40,7 +40,7 @@
|
||||
</if>
|
||||
FROM order_goods g
|
||||
LEFT JOIN order_plate a ON g.id = a.goods_id and a.deleted = 0
|
||||
LEFT JOIN orders o ON o.id = a.order_id and o.deleted = 0
|
||||
JOIN orders o ON o.id = a.order_id and o.deleted = 0
|
||||
WHERE g.deleted = 0
|
||||
AND o.order_date BETWEEN #{req.createTime[0]} AND #{req.createTime[1]}
|
||||
and g.goods_id in
|
||||
@@ -60,8 +60,8 @@
|
||||
where g.deleted = 0
|
||||
and o.order_date between #{req.createTime[0]} and #{req.createTime[1]}
|
||||
group by g.goods_id
|
||||
having orderArea > 0
|
||||
order by null;
|
||||
order by orderArea
|
||||
limit 10;
|
||||
</select>
|
||||
|
||||
<select id="selectTopTenPlateAreaListGroupByOrderDate"
|
||||
|
||||
+1
-1
@@ -12,11 +12,11 @@ public final class ErrorCodeConstants {
|
||||
|
||||
// ========== UREPORT template模块 1-003-001-000 ==========
|
||||
public static final ErrorCode TEMPLATE_NOT_EXISTS = new ErrorCode(1_003_001_001, "报表模板信息不存在");
|
||||
public static final ErrorCode DATATEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR = new ErrorCode(1_003_001_002, "内置模板操作权限不足");
|
||||
|
||||
// ========== UREPORT datasource模块 1-003-002-000 ==========
|
||||
public static final ErrorCode DATASOURCE_NOT_EXISTS = new ErrorCode(1_003_002_001, "报表数据源不存在");
|
||||
public static final ErrorCode DATASOURCE_CONNECT_FAIL = new ErrorCode(1_003_002_002, "报表数据源连接失败");
|
||||
public static final ErrorCode DATASOURCE_BUILDIN_OPERATION_PERMISSION_ERROR = new ErrorCode(1_003_002_003, "内置报表数据源只能由超级管理员操作");
|
||||
|
||||
|
||||
// ========== UREPORT dataset模块 1-003-003-000 ==========
|
||||
|
||||
+5
-5
@@ -37,14 +37,14 @@ public class ReportDatasetController {
|
||||
|
||||
@PutMapping("/dataset")
|
||||
@Operation(summary = "创建报表数据集")
|
||||
@PreAuthorize("@ss.hasPermission('report:dataset:create')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:dataset:create')")
|
||||
public CommonResult<Long> createDataset(@Valid @RequestBody ReportDatasetSaveReqVO createReqVO) {
|
||||
return success(datasetService.createDataset(createReqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/dataset")
|
||||
@Operation(summary = "更新报表数据集")
|
||||
@PreAuthorize("@ss.hasPermission('report:dataset:update')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:dataset:update')")
|
||||
public CommonResult<Boolean> updateDataset(@Valid @RequestBody ReportDatasetSaveReqVO updateReqVO) {
|
||||
datasetService.updateDataset(updateReqVO);
|
||||
return success(true);
|
||||
@@ -53,7 +53,7 @@ public class ReportDatasetController {
|
||||
@DeleteMapping("/dataset/{id}")
|
||||
@Operation(summary = "删除报表数据集")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('report:dataset:delete')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:dataset:delete')")
|
||||
public CommonResult<Boolean> deleteDataset(@PathVariable("id") Long id) {
|
||||
datasetService.deleteDataset(id);
|
||||
return success(true);
|
||||
@@ -62,7 +62,7 @@ public class ReportDatasetController {
|
||||
@GetMapping("/dataset/{id}")
|
||||
@Operation(summary = "获得报表数据集")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||
public CommonResult<ReportDatasetRespVO> getDataset(@PathVariable("id") Long id) {
|
||||
ReportDatasetDO dataset = datasetService.getDataset(id);
|
||||
return success(BeanUtils.toBean(dataset, ReportDatasetRespVO.class));
|
||||
@@ -70,7 +70,7 @@ public class ReportDatasetController {
|
||||
|
||||
@GetMapping("/datasets")
|
||||
@Operation(summary = "获取数据源下的报表数据集列表")
|
||||
@PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:dataset:query')")
|
||||
public CommonResult<List<ReportDatasetRespVO>> getDatasetPage(@RequestParam(value = "datasourceId") Long datasourceId,
|
||||
@RequestParam(value = "name", required = false) String name) {
|
||||
ReportDatasetReqVO reqVO = new ReportDatasetReqVO(name, datasourceId);
|
||||
|
||||
+11
-11
@@ -43,14 +43,14 @@ public class ReportDatasourceController {
|
||||
|
||||
@PutMapping("/datasource")
|
||||
@Operation(summary = "创建报表数据源")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:create')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:create')")
|
||||
public CommonResult<Long> createDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO createReqVO) {
|
||||
return success(datasourceService.createDatasource(createReqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/datasource")
|
||||
@Operation(summary = "更新报表数据源")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:update')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:update')")
|
||||
public CommonResult<Boolean> updateDatasource(@Valid @RequestBody ReportDatasourceSaveReqVO updateReqVO) {
|
||||
datasourceService.updateDatasource(updateReqVO);
|
||||
return success(true);
|
||||
@@ -59,7 +59,7 @@ public class ReportDatasourceController {
|
||||
@DeleteMapping("/datasource/{id}")
|
||||
@Operation(summary = "删除报表数据源")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:delete')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:delete')")
|
||||
public CommonResult<Boolean> deleteDatasource(@PathVariable("id") Long id) {
|
||||
datasourceService.deleteDatasource(id);
|
||||
return success(true);
|
||||
@@ -68,7 +68,7 @@ public class ReportDatasourceController {
|
||||
@GetMapping("/datasource/{id}")
|
||||
@Operation(summary = "获取报表数据源")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<ReportDatasourceRespVO> getDatasource(@PathVariable("id") Long id) {
|
||||
ReportDatasourceDO datasource = datasourceService.getDatasource(id);
|
||||
return success(BeanUtils.toBean(datasource, ReportDatasourceRespVO.class));
|
||||
@@ -76,35 +76,35 @@ public class ReportDatasourceController {
|
||||
|
||||
@GetMapping("/{templateId}/datasources")
|
||||
@Operation(summary = "获取报表模板下的报表数据源")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<List<ReportDatasourceRespVO>> getDatasourcePage(@PathVariable(value = "templateId") Long templateId) {
|
||||
return success(BeanUtils.toBean(datasourceService.getTemplateDatasourceList(ReportDatasourceReqVO.builder().templateId(templateId).build()), ReportDatasourceRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/datasource/beans")
|
||||
@Operation(summary = "获取springbean数据源列表")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<List<ReportBeanDatasourceRespVO>> getBeanDatasourceList() {
|
||||
return success(datasourceService.getBeanDatasourceList());
|
||||
}
|
||||
|
||||
@GetMapping("/datasource/bean/methods")
|
||||
@Operation(summary = "获取springbean数据源方法类表")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<List<String>> getBeanDatasourceList(@RequestParam(value = "beanId") String beanId) {
|
||||
return success(datasourceService.loadBeanMethods(beanId));
|
||||
}
|
||||
|
||||
@GetMapping("/buildin/datasources")
|
||||
@Operation(summary = "获取内置数据源")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<List<ReportDatasourceRespVO>> getBuildinDatasources() {
|
||||
return success(BeanUtils.toBean(datasourceService.getBuildinDatasources(), ReportDatasourceRespVO.class));
|
||||
}
|
||||
|
||||
@PostMapping("/datasource/connect")
|
||||
@Operation(summary = "测试数据源连接")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<Boolean> testDatasourceConnect(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
||||
boolean connResult = datasourceService.testConnect(reqVO);
|
||||
return connResult ? success(true) : error(DATASOURCE_CONNECT_FAIL);
|
||||
@@ -112,14 +112,14 @@ public class ReportDatasourceController {
|
||||
|
||||
@PostMapping("/datasource/tables")
|
||||
@Operation(summary = "获取数据源表列表")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<List<Map<String, String>>> getDatasourceTables(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
||||
return success(datasourceService.getDatasourceTables(reqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/datasource/table/fields")
|
||||
@Operation(summary = "获取数据源表字段")
|
||||
@PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:datasource:query')")
|
||||
public CommonResult<List<ReportDatasetFieldVO>> getDatasourceTableFields(@RequestBody ReportDatasourceTestConnReqVO reqVO) {
|
||||
return success(datasourceService.getTableFields(reqVO));
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,13 +1,13 @@
|
||||
package com.cf.imes.module.report.controller.admin.datasource.vo;
|
||||
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetRespVO;
|
||||
import com.cf.imes.module.report.enums.datasource.ReportDatasourceTypeEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
@@ -28,10 +28,7 @@ public class ReportDatasourceRespVO {
|
||||
@Schema(description = "数据源名称", example = "测试库")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "数据源类型,jdbc、spring", example = "jdbc")
|
||||
private ReportDatasourceTypeEnum dsType;
|
||||
|
||||
@Schema(description = "模板类型,0内置、1自定义", example = "0")
|
||||
@Schema(description = "数据源类型,jdbc、spring、buildin、api", example = "0")
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "数据源驱动类",example = "com.mysql.cj.jdbc.Driver")
|
||||
@@ -51,4 +48,7 @@ public class ReportDatasourceRespVO {
|
||||
|
||||
@Schema(description = "数据集")
|
||||
private List<ReportDatasetRespVO> datasets;
|
||||
|
||||
@Schema(description = "请求头参数")
|
||||
private List<Map<String, String>> headers;
|
||||
}
|
||||
|
||||
+6
-7
@@ -2,7 +2,6 @@ package com.cf.imes.module.report.controller.admin.datasource.vo;
|
||||
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetSaveReqVO;
|
||||
import com.cf.imes.module.report.validation.datasource.ReportDatasourceTypeInEnum;
|
||||
import com.cf.imes.module.report.validation.template.ReportTemplateTypeInEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -13,6 +12,7 @@ import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Gqr
|
||||
@@ -36,13 +36,9 @@ public class ReportDatasourceSaveReqVO implements Serializable {
|
||||
@Schema(description = "数据源名称", example = "测试库")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
||||
@ReportTemplateTypeInEnum
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "数据源类型,jdbc、spring", example = "jdbc")
|
||||
@Schema(description = "数据源类型,jdbc、spring、buildin、api", example = "1")
|
||||
@ReportDatasourceTypeInEnum
|
||||
private String dsType;
|
||||
private String type;
|
||||
|
||||
@Schema(description = "spring型数据源id")
|
||||
private String beanId;
|
||||
@@ -64,4 +60,7 @@ public class ReportDatasourceSaveReqVO implements Serializable {
|
||||
|
||||
@Schema(description = "数据集")
|
||||
private List<ReportDatasetSaveReqVO> datasets = new ArrayList<>();
|
||||
|
||||
@Schema(description = "请求头参数")
|
||||
private List<Map<String, String>> headers;
|
||||
}
|
||||
|
||||
+24
-7
@@ -1,10 +1,13 @@
|
||||
package com.cf.imes.module.report.controller.admin.template;
|
||||
|
||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||
import com.bstek.designer.excel.ExcelParserUtils;
|
||||
import com.bstek.ureport.definition.ReportDefinition;
|
||||
import com.bstek.ureport.export.ExportUtils;
|
||||
import com.bstek.ureport.export.ProducerEnum;
|
||||
import com.bstek.ureport.export.html.HtmlReport;
|
||||
import com.bstek.ureport.model.Report;
|
||||
import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.pojo.CommonResult;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.module.report.api.template.dto.ReportTemplateGenerateReqDTO;
|
||||
@@ -18,9 +21,11 @@ import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -48,14 +53,14 @@ public class ReportTemplateController {
|
||||
|
||||
@PutMapping("/template")
|
||||
@Operation(summary = "创建报表模板信息")
|
||||
@PreAuthorize("@ss.hasPermission('report:template:create')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:create')")
|
||||
public CommonResult<Long> createTemplate(@Valid @RequestBody ReportTemplateSaveReqVO createReqVO) {
|
||||
return success(templateService.createReportTemplate(createReqVO));
|
||||
}
|
||||
|
||||
@PostMapping("/template")
|
||||
@Operation(summary = "更新报表模板信息")
|
||||
@PreAuthorize("@ss.hasPermission('report:template:update')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:update')")
|
||||
public CommonResult<Boolean> updateTemplate(@Valid @RequestBody ReportTemplateSaveReqVO updateReqVO) {
|
||||
templateService.updateReportTemplate(updateReqVO);
|
||||
return success(true);
|
||||
@@ -64,7 +69,7 @@ public class ReportTemplateController {
|
||||
@DeleteMapping("/template/{id}")
|
||||
@Operation(summary = "删除报表模板信息")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('report:template:delete')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:delete')")
|
||||
public CommonResult<Boolean> deleteReportTemplate(@PathVariable("id") Long id) {
|
||||
templateService.deleteReportTemplate(id);
|
||||
return success(true);
|
||||
@@ -73,14 +78,14 @@ public class ReportTemplateController {
|
||||
@GetMapping("/template/{id}")
|
||||
@Operation(summary = "获取报表模板信息")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
public CommonResult<ReportDefinitionWrapper> getReportTemplate(@PathVariable("id") Long id) {
|
||||
return success(templateService.getReportTemplateDefinition(id));
|
||||
}
|
||||
|
||||
@GetMapping("/templates")
|
||||
@Operation(summary = "获取报表模板信息列表")
|
||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
public CommonResult<List<ReportTemplateRespVO>> getTemplatePage(@RequestParam(value = "name", required = false) String name) {
|
||||
ReportTemplateReqVO reqVO = new ReportTemplateReqVO(name, null);
|
||||
return success(BeanUtils.toBean(templateService.getReportTemplateList(reqVO), ReportTemplateRespVO.class));
|
||||
@@ -88,14 +93,14 @@ public class ReportTemplateController {
|
||||
|
||||
@PostMapping("/template/preview")
|
||||
@Operation(summary = "模板预览")
|
||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
public CommonResult<HtmlReport> preview(@Valid @RequestBody ReportTemplatePreviewPageParametersVO pageParametersVO) {
|
||||
return success(templateService.preview(pageParametersVO));
|
||||
}
|
||||
|
||||
@PostMapping("/template/export")
|
||||
@Operation(summary = "模板导出")
|
||||
@PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:query')")
|
||||
public void generateTemplate(@Valid @RequestBody ReportTemplateGenerateReqDTO reqDTO, HttpServletResponse response) {
|
||||
OutputStream out = null;
|
||||
try {
|
||||
@@ -109,4 +114,16 @@ public class ReportTemplateController {
|
||||
IOUtils.closeQuietly(out);
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/template/excel/import")
|
||||
@Operation(summary = "导入excel模板")
|
||||
// @PreAuthorize("@ss.hasPermission('report:template:import')")
|
||||
public ReportDefinitionWrapper importExcel(@RequestParam("file") MultipartFile file) {
|
||||
ReportDefinition report = ExcelParserUtils.parser(file);
|
||||
if (report != null) {
|
||||
report.setReportFullName("");
|
||||
return new ReportDefinitionWrapper(report);
|
||||
}
|
||||
throw new ServiceException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "文件未识别");
|
||||
}
|
||||
}
|
||||
|
||||
-5
@@ -1,7 +1,6 @@
|
||||
package com.cf.imes.module.report.controller.admin.template.vo;
|
||||
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceSaveReqVO;
|
||||
import com.cf.imes.module.report.validation.template.ReportTemplateTypeInEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
@@ -34,10 +33,6 @@ public class ReportTemplateSaveReqVO {
|
||||
@Schema(description = "数据源")
|
||||
private List<ReportDatasourceSaveReqVO> datasource = new ArrayList<>();
|
||||
|
||||
@Schema(description = "模板类型,0内置、1自定义", example = "1")
|
||||
@ReportTemplateTypeInEnum
|
||||
private Integer type;
|
||||
|
||||
@Schema(description = "备注", example = "该模板仅供生产使用")
|
||||
private String remark;
|
||||
}
|
||||
|
||||
+13
-8
@@ -5,12 +5,18 @@ import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.cf.imes.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.cf.imes.framework.mybatis.core.type.CompressObjectListTypeHandler;
|
||||
import com.cf.imes.module.report.dal.dataobject.dataset.ReportDatasetDO;
|
||||
import com.cf.imes.module.report.enums.datasource.ReportDatasourceTypeEnum;
|
||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||
import lombok.*;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 报表数据源DO
|
||||
@@ -18,7 +24,7 @@ import java.util.List;
|
||||
* @author Gqr
|
||||
* @since 2024/7/8 11:01
|
||||
*/
|
||||
@TableName("report_datasource")
|
||||
@TableName(value = "report_datasource", autoResultMap = true)
|
||||
@KeySequence("report_datasource_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@@ -40,15 +46,11 @@ public class ReportDatasourceDO extends BaseDO {
|
||||
* 数据源名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 模板类型,jdbc、spring
|
||||
*/
|
||||
private ReportDatasourceTypeEnum dsType;
|
||||
|
||||
/**
|
||||
* 模板类型,0内置、1自定义
|
||||
*/
|
||||
private ReportTemplateTypeEnum type;
|
||||
private ReportDatasourceTypeEnum type;
|
||||
|
||||
/**
|
||||
* spring型数据源id
|
||||
@@ -84,4 +86,7 @@ public class ReportDatasourceDO extends BaseDO {
|
||||
*/
|
||||
@TableField(exist = false)
|
||||
private List<ReportDatasetDO> datasets;
|
||||
|
||||
@TableField(typeHandler = CompressObjectListTypeHandler.class)
|
||||
private List<Map<String, String>> headers;
|
||||
}
|
||||
|
||||
+4
-2
@@ -13,8 +13,10 @@ import lombok.Getter;
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ReportDatasourceTypeEnum {
|
||||
JDBC(0,"jdbc"),
|
||||
SPRING(1,"spring");
|
||||
JDBC(0, "jdbc"),
|
||||
SPRING(1, "spring"),
|
||||
BUILDIN(2, "buildin"),
|
||||
API(3, "api");
|
||||
|
||||
@EnumValue
|
||||
private final Integer code;
|
||||
|
||||
+2
-52
@@ -12,8 +12,6 @@ import com.cf.imes.framework.common.exception.ServiceException;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetFieldVO;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetParameterVO;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
||||
@@ -58,7 +56,6 @@ import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_GET_FIE
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_ILLEGAL;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_INJECTION_RISK;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASET_SQL_REQUIRED;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_BUILDIN_OPERATION_PERMISSION_ERROR;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATASOURCE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -89,12 +86,8 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
@Override
|
||||
public Long createDatasource(ReportDatasourceSaveReqVO createReqVO) {
|
||||
ReportDatasourceDO datasource = BeanUtils.toBean(createReqVO, ReportDatasourceDO.class);
|
||||
// 校验内置数据源操作权限
|
||||
validateBuildinsource(datasource);
|
||||
// 插入
|
||||
datasourceMapper.insert(datasource);
|
||||
// 解析数据集
|
||||
analyzeDataset(datasource);
|
||||
// 返回
|
||||
return datasource.getId();
|
||||
}
|
||||
@@ -104,54 +97,10 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
// 校验存在
|
||||
validateDatasourceExists(updateReqVO.getId());
|
||||
ReportDatasourceDO updateObj = BeanUtils.toBean(updateReqVO, ReportDatasourceDO.class);
|
||||
// 校验内置数据源操作权限
|
||||
validateBuildinsource(updateObj);
|
||||
// 更新
|
||||
datasourceMapper.updateById(updateObj);
|
||||
// 解析数据集
|
||||
analyzeDataset(updateObj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验只有超管可以操作内置数据源
|
||||
*/
|
||||
private void validateBuildinsource(ReportDatasourceDO datasource) {
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
boolean isSuperAdmin = loginUser != null && loginUser.getIsSupAdmin();
|
||||
// 非超管不能操作内置数据源
|
||||
if (ReportTemplateTypeEnum.SYSTEM.equals(datasource.getType()) && !isSuperAdmin) {
|
||||
throw exception(DATASOURCE_BUILDIN_OPERATION_PERMISSION_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析数据源下的数据集
|
||||
*
|
||||
* @param datasource
|
||||
*/
|
||||
private void analyzeDataset(ReportDatasourceDO datasource) {
|
||||
List<ReportDatasetDO> datasets = datasource.getDatasets();
|
||||
List<ReportDatasetDO> batchInsertDataset = new ArrayList<>();
|
||||
List<ReportDatasetDO> batchupdateDataset = new ArrayList<>();
|
||||
datasets.forEach(dataset -> {
|
||||
// 更新/新增数据集
|
||||
if (ObjectUtil.isNotNull(dataset.getId())) {
|
||||
batchupdateDataset.add(dataset);
|
||||
} else {
|
||||
dataset.setDatasourceId(datasource.getId());
|
||||
batchInsertDataset.add(dataset);
|
||||
}
|
||||
});
|
||||
|
||||
// 批量插入数据集
|
||||
if (CollUtil.isNotEmpty(batchInsertDataset)) {
|
||||
datasetMapper.insertBatch(batchInsertDataset);
|
||||
}
|
||||
// 批量更新数据集
|
||||
if (CollUtil.isNotEmpty(batchupdateDataset)) {
|
||||
datasetMapper.updateBatch(batchupdateDataset);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteDatasource(Long id) {
|
||||
@@ -159,6 +108,8 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
validateDatasourceExists(id);
|
||||
// 删除
|
||||
datasourceMapper.deleteById(id);
|
||||
// 删除关联数据集
|
||||
datasetMapper.delete(new LambdaQueryWrapperX<ReportDatasetDO>().eq(ReportDatasetDO::getDatasourceId, id));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -185,7 +136,6 @@ public class ReportDatasourceServiceImpl implements ReportDatasourceService {
|
||||
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>()
|
||||
.eqIfPresent(ReportDatasourceDO::getTemplateId, reqVO.getTemplateId())
|
||||
.likeIfPresent(ReportDatasourceDO::getName, reqVO.getName())
|
||||
.eqIfPresent(ReportDatasourceDO::getDsType, reqVO.getType())
|
||||
.orderByDesc(ReportDatasourceDO::getCreateTime));
|
||||
// 查询数据集
|
||||
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
||||
|
||||
+93
-13
@@ -5,15 +5,18 @@ import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.URLUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.bstek.designer.bean.PreviewPageParameters;
|
||||
import com.bstek.designer.bean.PreviewParameters;
|
||||
import com.bstek.designer.bean.ReportDefinitionWrapper;
|
||||
import com.bstek.ureport.build.paging.Page;
|
||||
import com.bstek.ureport.definition.Paper;
|
||||
import com.bstek.ureport.definition.ReportDefinition;
|
||||
import com.bstek.ureport.definition.dataset.ApiDatasetDefinition;
|
||||
import com.bstek.ureport.definition.dataset.BeanDatasetDefinition;
|
||||
import com.bstek.ureport.definition.dataset.DatasetDefinition;
|
||||
import com.bstek.ureport.definition.dataset.SqlDatasetDefinition;
|
||||
import com.bstek.ureport.definition.datasource.ApiDatasourceDefinition;
|
||||
import com.bstek.ureport.definition.datasource.DatasourceDefinition;
|
||||
import com.bstek.ureport.definition.datasource.JdbcDatasourceDefinition;
|
||||
import com.bstek.ureport.definition.datasource.SpringBeanDatasourceDefinition;
|
||||
@@ -27,6 +30,9 @@ import com.bstek.ureport.model.Report;
|
||||
import com.bstek.ureport.parser.ReportParser;
|
||||
import com.cf.imes.framework.common.util.object.BeanUtils;
|
||||
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.cf.imes.framework.organ.core.aop.OrganIgnore;
|
||||
import com.cf.imes.framework.security.core.LoginUser;
|
||||
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
|
||||
import com.cf.imes.module.report.api.template.dto.ReportTemplateGenerateReqDTO;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetSaveReqVO;
|
||||
@@ -38,7 +44,10 @@ import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSave
|
||||
import com.cf.imes.module.report.dal.dataobject.dataset.ReportDatasetDO;
|
||||
import com.cf.imes.module.report.dal.dataobject.datasource.ReportDatasourceDO;
|
||||
import com.cf.imes.module.report.dal.dataobject.template.ReportTemplateDO;
|
||||
import com.cf.imes.module.report.dal.mysql.dataset.ReportDatasetMapper;
|
||||
import com.cf.imes.module.report.dal.mysql.datasource.ReportDatasourceMapper;
|
||||
import com.cf.imes.module.report.dal.mysql.template.ReportTemplateMapper;
|
||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||
import com.cf.imes.module.report.service.dataset.ReportDatasetService;
|
||||
import com.cf.imes.module.report.service.datasource.ReportDatasourceService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -49,11 +58,13 @@ import org.springframework.validation.annotation.Validated;
|
||||
import javax.annotation.Resource;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.cf.imes.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.DATATEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR;
|
||||
import static com.cf.imes.module.report.enums.ErrorCodeConstants.TEMPLATE_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
@@ -74,6 +85,12 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
@Resource
|
||||
private ReportDatasetService datasetService;
|
||||
|
||||
@Resource
|
||||
private ReportDatasourceMapper datasourceMapper;
|
||||
|
||||
@Resource
|
||||
private ReportDatasetMapper datasetMapper;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Long createReportTemplate(ReportTemplateSaveReqVO createReqVO) {
|
||||
@@ -84,6 +101,14 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
}
|
||||
// 新增模板
|
||||
ReportTemplateDO template = BeanUtils.toBean(createReqVO, ReportTemplateDO.class);
|
||||
// 超管创建的作为内置模板
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
boolean isSuperAdmin = loginUser != null && loginUser.getIsSupAdmin();
|
||||
if (isSuperAdmin) {
|
||||
template.setType(ReportTemplateTypeEnum.SYSTEM);
|
||||
} else {
|
||||
template.setType(ReportTemplateTypeEnum.CUSTOM);
|
||||
}
|
||||
templateMapper.insert(template);
|
||||
Long templateId = template.getId();
|
||||
// 解析数据源
|
||||
@@ -134,10 +159,13 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateReportTemplate(ReportTemplateSaveReqVO updateReqVO) {
|
||||
Long templateId = updateReqVO.getId();
|
||||
// 校验存在
|
||||
validateTemplateExists(templateId);
|
||||
ReportTemplateDO reportTemplateDO = validateTemplateExists(templateId);
|
||||
// 校验内置模板操作权限
|
||||
validateSystemTemplate(reportTemplateDO);
|
||||
// url解码xml
|
||||
String content = updateReqVO.getContent();
|
||||
if (StringUtils.isNotEmpty(content)) {
|
||||
@@ -152,11 +180,36 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void deleteReportTemplate(Long id) {
|
||||
// 校验存在
|
||||
validateTemplateExists(id);
|
||||
ReportTemplateDO reportTemplateDO = validateTemplateExists(id);
|
||||
// 校验内置模板操作权限
|
||||
validateSystemTemplate(reportTemplateDO);
|
||||
// 删除
|
||||
templateMapper.deleteById(id);
|
||||
// 删除关联数据源
|
||||
List<ReportDatasourceDO> reportDatasourceDOS = datasourceMapper.selectList(new LambdaQueryWrapperX<ReportDatasourceDO>().eq(ReportDatasourceDO::getTemplateId, id));
|
||||
if (CollUtil.isNotEmpty(reportDatasourceDOS)) {
|
||||
// 模板下的数据源id
|
||||
List<Long> datasourceIds = reportDatasourceDOS.stream().map(ReportDatasourceDO::getId).toList();
|
||||
datasourceMapper.deleteBatchIds(datasourceIds);
|
||||
// 删除关联数据集
|
||||
datasetMapper.delete(new LambdaQueryWrapperX<ReportDatasetDO>().in(ReportDatasetDO::getDatasourceId, datasourceIds));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 校验只有超管可以操作内置模板
|
||||
*/
|
||||
private void validateSystemTemplate(ReportTemplateDO templateDO) {
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
boolean isSuperAdmin = loginUser != null && loginUser.getIsSupAdmin();
|
||||
// 非超管不能操作内置模板
|
||||
if (ReportTemplateTypeEnum.SYSTEM.equals(templateDO.getType()) && !isSuperAdmin) {
|
||||
throw exception(DATATEMPLATE_BUILDIN_OPERATION_PERMISSION_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -164,9 +217,12 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
private void validateTemplateExists(Long id) {
|
||||
if (templateMapper.selectById(id) == null) {
|
||||
private ReportTemplateDO validateTemplateExists(Long id) {
|
||||
ReportTemplateDO reportTemplateDO = templateMapper.selectById(id);
|
||||
if (reportTemplateDO == null) {
|
||||
throw exception(TEMPLATE_NOT_EXISTS);
|
||||
} else {
|
||||
return reportTemplateDO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,8 +252,14 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
// 查询模板
|
||||
ReportTemplateDO template = templateMapper.selectById(id);
|
||||
String xmlContent = template.getContent();
|
||||
InputStream is;
|
||||
if (StringUtils.isNotEmpty(xmlContent)) {
|
||||
is = new ByteArrayInputStream(xmlContent.getBytes());
|
||||
} else {
|
||||
is = this.getClass().getClassLoader().getResourceAsStream("templates/template.ureport.xml");
|
||||
}
|
||||
// 解析xml
|
||||
ReportDefinition reportDefinition = new ReportParser().parse(new ByteArrayInputStream(xmlContent.getBytes()), template.getName());
|
||||
ReportDefinition reportDefinition = new ReportParser().parse(is, template.getName());
|
||||
if (ObjectUtil.isNotNull(template)) {
|
||||
queryDatasource(template.getId(), reportDefinition);
|
||||
}
|
||||
@@ -218,34 +280,52 @@ public class ReportTemplateServiceImpl implements ReportTemplateService {
|
||||
// 查询数据集
|
||||
List<ReportDatasetDO> datasetList = datasetService.getDatasetList(ReportDatasetReqVO.builder().datasourceId(ds.getId()).build());
|
||||
List<DatasetDefinition> datasetDefinitions = new ArrayList<>();
|
||||
switch (ds.getDsType()) {
|
||||
case JDBC -> {
|
||||
// 忽略转换的字段名,手动转列表
|
||||
String ignorePropertieName = "datasets";
|
||||
switch (ds.getType()) {
|
||||
case JDBC, BUILDIN -> {
|
||||
// 转换对应的ureport对象
|
||||
JdbcDatasourceDefinition jdbcDatasourceDefinition = BeanUtil.copyProperties(ds, JdbcDatasourceDefinition.class, "datasets");
|
||||
JdbcDatasourceDefinition jdbcDatasourceDefinition = BeanUtil.copyProperties(ds, JdbcDatasourceDefinition.class, ignorePropertieName);
|
||||
datasetDefinitions.addAll(BeanUtils.toBean(datasetList, SqlDatasetDefinition.class));
|
||||
jdbcDatasourceDefinition.setDatasets(datasetDefinitions);
|
||||
datasourceDefinitions.add(jdbcDatasourceDefinition);
|
||||
}
|
||||
case SPRING -> {
|
||||
// 转换对应的ureport对象
|
||||
SpringBeanDatasourceDefinition springBeanDatasourceDefinition = BeanUtil.copyProperties(ds, SpringBeanDatasourceDefinition.class, "datasets");
|
||||
SpringBeanDatasourceDefinition springBeanDatasourceDefinition = BeanUtil.copyProperties(ds, SpringBeanDatasourceDefinition.class, ignorePropertieName);
|
||||
datasetDefinitions.addAll(BeanUtils.toBean(datasetList, BeanDatasetDefinition.class));
|
||||
springBeanDatasourceDefinition.setDatasets(datasetDefinitions);
|
||||
datasourceDefinitions.add(springBeanDatasourceDefinition);
|
||||
}
|
||||
case API -> {
|
||||
// 转换对应的ureport对象
|
||||
ApiDatasourceDefinition apiDatasourceDefinition = BeanUtil.copyProperties(ds, ApiDatasourceDefinition.class, ignorePropertieName);
|
||||
datasetDefinitions.addAll(BeanUtils.toBean(datasetList, ApiDatasetDefinition.class));
|
||||
apiDatasourceDefinition.setDatasets(datasetDefinitions);
|
||||
datasourceDefinitions.add(apiDatasourceDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
reportDefinition.setDatasources(datasourceDefinitions);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OrganIgnore
|
||||
public List<ReportTemplateDO> getReportTemplateList(ReportTemplateReqVO reqVO) {
|
||||
return templateMapper.selectList(new LambdaQueryWrapperX<ReportTemplateDO>()
|
||||
.likeIfPresent(ReportTemplateDO::getName, reqVO.getName())
|
||||
.eqIfPresent(ReportTemplateDO::getType, reqVO.getType())
|
||||
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
|
||||
LambdaQueryWrapper<ReportTemplateDO> queryWrapper = new LambdaQueryWrapperX<ReportTemplateDO>().likeIfPresent(ReportTemplateDO::getName, reqVO.getName())
|
||||
.orderByDesc(ReportTemplateDO::getCreateTime)
|
||||
// 不返回content xml,点击具体的模板中返回xml
|
||||
.select(ReportTemplateDO::getId, ReportTemplateDO::getName, ReportTemplateDO::getCreateTime, ReportTemplateDO::getRemark));
|
||||
.select(ReportTemplateDO::getId, ReportTemplateDO::getName, ReportTemplateDO::getCreateTime, ReportTemplateDO::getRemark);
|
||||
if (loginUser != null && Boolean.FALSE.equals(loginUser.getIsSupAdmin())) {
|
||||
// 普通用户查看机构下的和system模板
|
||||
queryWrapper.or(wrapper -> wrapper
|
||||
.eq(ReportTemplateDO::getOrganId, loginUser.getOrganId())
|
||||
.eq(ReportTemplateDO::getType, ReportTemplateTypeEnum.CUSTOM))
|
||||
.or(wrapper -> wrapper.eq(ReportTemplateDO::getType, ReportTemplateTypeEnum.SYSTEM));
|
||||
}
|
||||
// 超管查看全部
|
||||
return templateMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ import java.lang.annotation.Target;
|
||||
validatedBy = {ReportDatasourceTypeInEnumValidator.class}
|
||||
)
|
||||
public @interface ReportDatasourceTypeInEnum {
|
||||
String message() default "数据源类型[dsType]错误,请检查是否jdbc/spring";
|
||||
String message() default "数据源类型[type]错误,请检查是否jdbc/spring/buildin/api";
|
||||
|
||||
Class<?>[] groups() default {};
|
||||
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ureport xmlns="http://www.example.org/ureport2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.example.org/ureport2 http://www.example.org/ureport2 ">
|
||||
<cell expand="None" name="A1" col="1" row="1">
|
||||
<simple-value><![CDATA[]]></simple-value>
|
||||
<cell-style font-size="10" font-family="宋体" align="left" valign="middle"></cell-style>
|
||||
</cell>
|
||||
<row row-number="1" height="18"/>
|
||||
<column col-number="1" width="80"/>
|
||||
<paper type="A4" orientation="portrait" paging-mode="fitpage"></paper>
|
||||
</ureport>
|
||||
+1
-4
@@ -8,7 +8,6 @@ import com.cf.imes.module.report.controller.admin.dataset.vo.ReportDatasetSaveRe
|
||||
import com.cf.imes.module.report.controller.admin.datasource.vo.ReportDatasourceSaveReqVO;
|
||||
import com.cf.imes.module.report.controller.admin.template.vo.ReportTemplateSaveReqVO;
|
||||
import com.cf.imes.module.report.enums.datasource.ReportDatasourceTypeEnum;
|
||||
import com.cf.imes.module.report.enums.template.ReportTemplateTypeEnum;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,7 +29,6 @@ public abstract class ReportCommonServiceImplTest {
|
||||
.id(id)
|
||||
.name("单元测试模板")
|
||||
.content(JsonUtil.zipString(TEMPLATE))
|
||||
.type(ReportTemplateTypeEnum.SYSTEM.getType())
|
||||
.remark(RandomUtils.randomString())
|
||||
.datasource(new ArrayList<>())
|
||||
.build();
|
||||
@@ -42,8 +40,7 @@ public abstract class ReportCommonServiceImplTest {
|
||||
.id(id)
|
||||
.name("单元测试数据源")
|
||||
.templateId(reportId)
|
||||
.dsType(ReportDatasourceTypeEnum.SPRING.getDesc())
|
||||
.type(ReportTemplateTypeEnum.SYSTEM.getType())
|
||||
.type(ReportDatasourceTypeEnum.SPRING.getDesc())
|
||||
.driver("com.mysql.cj.jdbc.Driver")
|
||||
.url("jdbc:mysql://192.168.1.205:3307/imes_base?allowMultiQueries=true&useUnicode=true&useSSL=false&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&nullCatalogMeansCurrent=true")
|
||||
.username("root")
|
||||
|
||||
Reference in New Issue
Block a user