affcfacc90ffec0e1efc306d98b14dddfcf5054d.svn-base 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. package org.jeecg.modules.online.cgreport.service.impl;
  2. import java.util.*;
  3. import javax.annotation.Resource;
  4. import com.alibaba.fastjson.JSONObject;
  5. import org.jeecg.modules.online.cgreport.entity.DiagramConfiguration;
  6. import org.jeecg.modules.online.cgreport.entity.DiagramFieldConfiguration;
  7. import org.jeecg.modules.online.cgreport.mapper.DiagramConfigurationMapper;
  8. import org.jeecg.modules.online.cgreport.service.IDiagramConfigurationService;
  9. import org.jeecg.modules.online.cgreport.service.impl.DiagramFieldConfigurationServiceImpl;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.stereotype.Service;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  14. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  15. import org.springframework.util.StringUtils;
  16. /**
  17. * @Description: 图表配置
  18. */
  19. @Service
  20. public class DiagramConfigurationServiceImpl extends ServiceImpl<DiagramConfigurationMapper, DiagramConfiguration>
  21. implements IDiagramConfigurationService {
  22. @Autowired
  23. private DiagramFieldConfigurationServiceImpl diagramFieldConfigurationService;
  24. @Resource
  25. private DiagramConfigurationMapper diagramConfigurationMapper;
  26. @Override
  27. @Transactional(rollbackFor = Exception.class)
  28. public void add(DiagramConfiguration diagramConfiguration) {
  29. // 保存主表信息
  30. this.save(diagramConfiguration);
  31. // 保存子表信息
  32. if (diagramConfiguration != null && diagramConfiguration.getDiagramFieldConfigurationList() != null
  33. && !diagramConfiguration.getDiagramFieldConfigurationList().isEmpty()) {
  34. diagramConfiguration.getDiagramFieldConfigurationList()
  35. .forEach(dfc -> dfc.setDiagramCode(diagramConfiguration.getCode()));
  36. this.diagramFieldConfigurationService.saveBatch(diagramConfiguration.getDiagramFieldConfigurationList());
  37. }
  38. }
  39. @Override
  40. @Transactional(rollbackFor = Exception.class)
  41. public void edit(DiagramConfiguration diagramConfiguration) {
  42. this.updateById(diagramConfiguration);
  43. // 更新子表信息
  44. Map<String, Object> columnMap = new HashMap<>();
  45. columnMap.put("DIAGRAM_CODE", diagramConfiguration.getCode());
  46. this.diagramFieldConfigurationService.removeByMap(columnMap);
  47. this.diagramFieldConfigurationService.saveBatch(diagramConfiguration.getDiagramFieldConfigurationList());
  48. }
  49. @Override
  50. @Transactional(rollbackFor = Exception.class)
  51. public void deleteById(String id) {
  52. DiagramConfiguration diagramConfiguration = super.getById(id);
  53. this.removeById(id);
  54. // 删除子表信息
  55. Map<String, Object> columnMap = new HashMap<>();
  56. columnMap.put("DIAGRAM_CODE", diagramConfiguration.getCode());
  57. this.diagramFieldConfigurationService.removeByMap(columnMap);
  58. }
  59. @Override
  60. @Transactional(rollbackFor = Exception.class)
  61. public void deleteBatch(String ids) {
  62. List<String> idList = Arrays.asList(ids.split(","));
  63. QueryWrapper<DiagramConfiguration> queryWrapper = new QueryWrapper<>();
  64. queryWrapper.in("ID", idList);
  65. List<DiagramConfiguration> diagramConfigurationList = super.list(queryWrapper);
  66. this.removeByIds(idList);
  67. // 删除子表信息
  68. if (diagramConfigurationList != null && !diagramConfigurationList.isEmpty()) {
  69. Map<String, Object> columnMap = new HashMap<>();
  70. for (DiagramConfiguration diagramConfiguration : diagramConfigurationList) {
  71. columnMap.clear();
  72. columnMap.put("DIAGRAM_CODE", diagramConfiguration.getCode());
  73. this.diagramFieldConfigurationService.removeByMap(columnMap);
  74. }
  75. }
  76. }
  77. @Override
  78. public List selectBySql(String sql) {
  79. return this.diagramConfigurationMapper.selectBySql(sql);
  80. }
  81. @Override
  82. public List<Map<String, Object>> handelTreeTableData(List<Map<String, Object>> dataList, String unfoldFieldName, String pid) {
  83. //根节点对象存放到这里
  84. List<Map<String, Object>> rootList = new ArrayList<>();
  85. //非最顶层根节点
  86. List<Map<String, Object>> bodyList = new ArrayList<>();
  87. for (Map<String, Object> data : dataList) {
  88. Map<String, Object> tempMap = data;
  89. // 处理属性排列顺序
  90. Map<String, Object> objMap = new LinkedHashMap<>();
  91. objMap.put("id", tempMap.get("id"));
  92. objMap.put(unfoldFieldName, tempMap.get(unfoldFieldName));
  93. objMap.put(pid, tempMap.get(pid));
  94. tempMap.remove(unfoldFieldName);
  95. tempMap.remove("id");
  96. tempMap.remove(pid);
  97. objMap.putAll(tempMap);
  98. if (objMap.get(pid).equals("0")) {
  99. rootList.add(objMap);
  100. } else {
  101. bodyList.add(objMap);
  102. }
  103. }
  104. return getTree(rootList, bodyList, pid);
  105. }
  106. private List<Map<String, Object>> getTree(List<Map<String, Object>> rootList, List<Map<String, Object>> bodyList, String pid) {
  107. if (bodyList.size() != 0){
  108. //声明一个map,用来过滤已操作过的数据
  109. Map<String,Object> map = new HashMap<>(bodyList.size());
  110. rootList.forEach(parent->getChild(parent,bodyList,map, pid));
  111. return rootList;
  112. }else{
  113. return rootList;
  114. }
  115. }
  116. private void getChild(Map<String, Object> parent, List<Map<String, Object>> bodyList, Map<String, Object> map, String pid) {
  117. List<Map<String, Object>> childList = new ArrayList<>();
  118. bodyList.stream().filter(c->!map.containsKey(c.get("id")))
  119. .filter(c->c.get(pid).equals(parent.get("id")))
  120. .forEach(c->{
  121. map.put(c.get("id").toString(), c.get(pid));
  122. getChild(c,bodyList,map, pid);
  123. childList.add(c);
  124. });
  125. if (childList.size() != 0) {
  126. parent.put("children", childList);
  127. }
  128. }
  129. @Override
  130. public String handelQuerySql(String cgrSql, JSONObject jsonO, List<DiagramFieldConfiguration> diagramFieldConfigurations) {
  131. List<String> fields = getFields(diagramFieldConfigurations);
  132. StringBuilder sbl = new StringBuilder();
  133. sbl.append("select * from (");
  134. sbl.append(cgrSql);
  135. sbl.append(") tt where 1 = 1");
  136. for (String key : jsonO.keySet()){
  137. if (!key.equals("templetCode") && fields.contains(key)) {
  138. JSONObject jsonObject = jsonO.getJSONObject(key);
  139. String queryMode = jsonObject.getString("queryType");
  140. if (queryMode.equals("group")) { // 范围查询
  141. String startValue = jsonObject.getString("startValue");
  142. String endValue = jsonObject.getString("endValue");
  143. if (!StringUtils.isEmpty(startValue) && !StringUtils.isEmpty(endValue)) {
  144. sbl.append(" and " + key + " >= '" + startValue + "' and " + key + " <= '" + endValue + "'");
  145. } else if (!StringUtils.isEmpty(startValue) && StringUtils.isEmpty(endValue)) {
  146. sbl.append(" and " + key + " >= '" + startValue + "'");
  147. } else if (StringUtils.isEmpty(startValue) && !StringUtils.isEmpty(endValue)) {
  148. sbl.append(" and " + key + " <= '" + endValue + "'");
  149. }
  150. } else if(queryMode.equals("more")){
  151. String val = jsonObject.getString("value");
  152. if (!StringUtils.isEmpty(val)) {
  153. String[] values = jsonObject.getString("value").split(",");
  154. sbl.append(" and " + key + " in (");
  155. for (int i=0; i< values.length; i++) {
  156. String value = values[i];
  157. if (i != values.length - 1) {
  158. sbl.append("'" + value + "',");
  159. } else {
  160. sbl.append("'" + value + "'");
  161. }
  162. }
  163. sbl.append(")");
  164. }
  165. } else { // 单值查询
  166. Object value = jsonObject.get("value");
  167. if (value instanceof Integer) {
  168. sbl.append(" and " + key + " = '" + value + "'");
  169. } else {
  170. sbl.append(" and " + key + " like '%" + value + "%'");
  171. }
  172. }
  173. }
  174. }
  175. return sbl.toString();
  176. }
  177. private static List<String> getFields(List<DiagramFieldConfiguration> diagramFieldConfigurations) {
  178. List<String> fields = new ArrayList<>();
  179. diagramFieldConfigurations.forEach(item -> {
  180. fields.add(item.getFieldName());
  181. });
  182. return fields;
  183. }
  184. }