|
@@ -0,0 +1,165 @@
|
|
|
+package com.ruoyi.system.service.impl;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import com.alibaba.fastjson2.JSON;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
+import com.ruoyi.system.entity.CommonEntity;
|
|
|
+import com.ruoyi.system.entity.DragTableStatistic;
|
|
|
+import com.ruoyi.system.entity.TableSql;
|
|
|
+import com.ruoyi.system.entity.vo.DragTableVo;
|
|
|
+import com.ruoyi.system.mapper.CommonMapper;
|
|
|
+import com.ruoyi.system.mapper.TableSqlMapper;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.ruoyi.system.mapper.DragTableStatisticMapper;
|
|
|
+import com.ruoyi.system.service.IDragTableStatisticService;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 动态表格统计Service业务层处理
|
|
|
+ *
|
|
|
+ * @author ruoyi
|
|
|
+ * @date 2023-10-27
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class DragTableStatisticServiceImpl implements IDragTableStatisticService
|
|
|
+{
|
|
|
+ @Autowired
|
|
|
+ private DragTableStatisticMapper dragTableStatisticMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TableSqlMapper tableSqlMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CommonMapper commonMapper;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public DragTableStatistic selectDragTableStatisticById(Long id)
|
|
|
+ {
|
|
|
+ return dragTableStatisticMapper.selectDragTableStatisticById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DragTableStatistic> selectDragTableStatisticList(DragTableStatistic dragTableStatistic)
|
|
|
+ {
|
|
|
+ return dragTableStatisticMapper.selectDragTableStatisticList(dragTableStatistic);
|
|
|
+ }
|
|
|
+
|
|
|
+ // SQL 条件的开始
|
|
|
+ public static final String SQL_START = "CONCAT(";
|
|
|
+
|
|
|
+ // SQL 超级查询常量
|
|
|
+ public static final String SQL_MIDDLE = "IFNULL( #{VAL}, '' )";
|
|
|
+
|
|
|
+ // sqlserver || DM 数据类型的超级查询常量
|
|
|
+ public static final String SQL_DM_SERVER_MIDDLE = "COALESCE( #{VAL}, '' )";
|
|
|
+
|
|
|
+ // SQL 条件的结束
|
|
|
+ public static final String SQL_END = "LIKE '%#{val}%'";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public int batchInsertDragTableStatistic(DragTableVo vo)
|
|
|
+ {
|
|
|
+ vo.getDragTableStatisticList().forEach(s -> s.setCreateBy(SecurityUtils.getUserId().toString()));
|
|
|
+
|
|
|
+ // 拼接sql查询条件
|
|
|
+ String SQL = "";
|
|
|
+ switch (SecurityUtils.getDatabaseType().toUpperCase()) {
|
|
|
+ case "MYSQL":
|
|
|
+ SQL += SQL_START;
|
|
|
+ for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += SQL_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
|
|
|
+ SQL += vo.getSearchFieldList().size() - 1 == i ? ")" : ",\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "DM":
|
|
|
+ case "SQLSERVER":
|
|
|
+ SQL += SQL_START;
|
|
|
+ for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += SQL_DM_SERVER_MIDDLE.replace("#{VAL}", vo.getSearchFieldList().get(i));
|
|
|
+ SQL += vo.getSearchFieldList().size() - 1 == i ? ",'')" : ",\n";
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "ORACLE":
|
|
|
+// SQL_START = "";
|
|
|
+ for (int i = 0; vo.getSearchFieldList().size() > i; i++) {
|
|
|
+ SQL += vo.getSearchFieldList().get(i);
|
|
|
+ SQL += (vo.getSearchFieldList().size() - 1 == i ? " " : "||");
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ String where = vo.getDtTableName() + ".del_flag = '0' AND "+ SQL + SQL_END;
|
|
|
+ vo.getTableSqlList().stream().forEach(t -> t.setTableCondition(where));
|
|
|
+
|
|
|
+ tableSqlMapper.batchInsertTableSql(vo.getTableSqlList());
|
|
|
+ return dragTableStatisticMapper.batchInsertDragTableStatistic(vo.getDragTableStatisticList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateDragTableStatistic(DragTableVo vo)
|
|
|
+ {
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteDragTableStatisticByIds(Long[] ids)
|
|
|
+ {
|
|
|
+ return dragTableStatisticMapper.deleteDragTableStatisticByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteDragTableStatisticByTableKey(String tableKey)
|
|
|
+ {
|
|
|
+ return dragTableStatisticMapper.deleteDragTableStatisticByTableKey(tableKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getInfoBySqlKey(String tableKey) {
|
|
|
+ Map<String,Object> map = new HashMap<>();
|
|
|
+ DragTableStatistic dragTableStatistic = new DragTableStatistic();
|
|
|
+ dragTableStatistic.setTableKey(tableKey);
|
|
|
+ List<DragTableStatistic> dragTableStatisticList = dragTableStatisticMapper.selectDragTableStatisticList(dragTableStatistic);
|
|
|
+ map.put("dragTableStatisticList",dragTableStatisticList);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DragTableStatistic> getStatisticList(CommonEntity commonEntity) {
|
|
|
+ // 根据sqlkey查询得到当前表单对应的sql
|
|
|
+ Map<String, Object> conditions = JSONObject.parseObject(JSON.toJSONString(commonEntity.getQueryMap()));
|
|
|
+ // 得到查询条件的值
|
|
|
+ String queryCriteriaValue =
|
|
|
+ conditions.containsKey("queryCriteriaValue") == true
|
|
|
+ ? conditions.get("queryCriteriaValue").toString() : "";
|
|
|
+ DragTableStatistic dragTableStatistic = new DragTableStatistic();
|
|
|
+ dragTableStatistic.setTableKey(conditions.get("tableKey").toString());
|
|
|
+ List<DragTableStatistic> dragTableStatisticList = dragTableStatisticMapper.selectDragTableStatisticList(dragTableStatistic);
|
|
|
+ return dragTableStatisticList.stream().map(d -> {
|
|
|
+ TableSql tableSql = tableSqlMapper.selectTableSqlByTSqlKey(d.getSqlKey());
|
|
|
+ // 得到需要执行的sql条件语句
|
|
|
+ String endSQL = tableSql.getTableCondition().replace("#{val}", queryCriteriaValue);
|
|
|
+ String sql = "";
|
|
|
+ if(StringUtils.hasLength(d.getStatisticObject())){
|
|
|
+ sql = tableSql.getTableSql() + " where " + endSQL + " and " + d.getStatisticField() + " like'"+d.getStatisticObject()+"'";
|
|
|
+ }else {
|
|
|
+ sql = tableSql.getTableSql() + " where " + endSQL;
|
|
|
+ }
|
|
|
+ List<CommonEntity> commonEntities = commonMapper.queryTableList(sql);
|
|
|
+ d.setResult(commonEntities.get(0) == null ? 0 : commonEntities.get(0).getResultMap().get("result") );
|
|
|
+ return d;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|