StrategysService.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package com.server;
  2. import com.dao.DashboardsMapper;
  3. import com.dao.StrategysBdMapper;
  4. import com.dao.StrategysChartMapper;
  5. import com.fasterxml.jackson.core.JsonProcessingException;
  6. import com.fasterxml.jackson.databind.ObjectMapper;
  7. import com.model.bo.Obj;
  8. import com.model.po.Strategys;
  9. import com.model.po.StrategysData;
  10. import com.model.pojo.RepCode;
  11. import com.model.pojo.RepEntity;
  12. import com.model.vo.configVo.ObjectInfo;
  13. import com.model.vo.configVo.StrategysInfo;
  14. import com.util.ScreenUtil;
  15. import org.springframework.beans.BeanUtils;
  16. import org.springframework.beans.factory.annotation.Autowired;
  17. import org.springframework.stereotype.Service;
  18. import java.util.*;
  19. @Service
  20. public class StrategysService {
  21. @Autowired
  22. ScreenUtil screenUtil;
  23. @Autowired
  24. StrategysBdMapper strategysBdMapper;
  25. @Autowired
  26. StrategysChartMapper strategysChartMapper;
  27. @Autowired
  28. ObjectMapper objectMapper;
  29. @Autowired
  30. DashboardsMapper dashboardsMapper;
  31. /*
  32. 保存数据源策略
  33. */
  34. public RepEntity addStrategys(StrategysInfo strategysInfo){
  35. Strategys strategys = new Strategys();
  36. BeanUtils.copyProperties(strategysInfo, strategys);
  37. String scr = screenUtil.screensUtil(strategysInfo.getRule(), "", "").getRet();
  38. strategys.setRule(scr);
  39. strategys.setRuleStr(String.valueOf(strategysInfo.getRule()));
  40. String type = strategysInfo.getType();
  41. if ("base".equals(type)){
  42. strategysBdMapper.addStrategys(strategys);
  43. }else {
  44. strategysChartMapper.addStrategys(strategys);
  45. }
  46. return new RepEntity(RepCode.success, strategys.getId());
  47. }
  48. /*
  49. 更新数据源策略
  50. */
  51. public RepEntity updateStrategys(StrategysInfo strategysInfo){
  52. Strategys strategys = new Strategys();
  53. BeanUtils.copyProperties(strategysInfo, strategys);
  54. String scr = screenUtil.screensUtil(strategysInfo.getRule(), "", "").getRet();
  55. strategys.setRule(scr);
  56. String ruleStr = null;
  57. try {
  58. ruleStr = objectMapper.writeValueAsString(strategysInfo.getRule());
  59. } catch (JsonProcessingException e) {
  60. e.printStackTrace();
  61. }
  62. strategys.setRuleStr(ruleStr);
  63. String type = strategysInfo.getType();
  64. if ("base".equals(type)) {
  65. strategysBdMapper.updataStrategys(strategys);
  66. }else {
  67. strategysChartMapper.updataStrategys(strategys);
  68. }
  69. return new RepEntity(RepCode.success);
  70. }
  71. /*
  72. 删除数据源策略
  73. */
  74. public RepEntity delDbStrategys(List<Integer> idList){
  75. strategysBdMapper.delStrategys(idList);
  76. Iterator isList = idList.iterator();
  77. while (isList.hasNext()){
  78. int id = (int) isList.next();
  79. strategysBdMapper.delObject(id);
  80. }
  81. return new RepEntity(RepCode.success);
  82. }
  83. /*
  84. 删除图表策略
  85. */
  86. public RepEntity delChartStrategys(List<Integer> idList){
  87. strategysChartMapper.delStrategys(idList);
  88. Iterator isList = idList.iterator();
  89. while (isList.hasNext()){
  90. int id = (int) isList.next();
  91. strategysChartMapper.delObject(id);
  92. }
  93. return new RepEntity(RepCode.success);
  94. }
  95. /*
  96. 查询数据源策略列表
  97. */
  98. public RepEntity getDbStrategys(int DbId){
  99. List<StrategysData> strategysDataList = new ArrayList<>();
  100. /*
  101. 获取id列表
  102. */
  103. List<Integer> idList = strategysBdMapper.getStrIdList(DbId);
  104. Iterator isList = idList.iterator();
  105. while (isList.hasNext()) {
  106. int id = (int) isList.next();
  107. List<Map<String, Object>> userGroupNameList = new ArrayList<>();
  108. List<Map<String, Object>> userNameList = new ArrayList<>();
  109. StrategysData strategysDatas = new StrategysData();
  110. Strategys strategys = strategysBdMapper.getStrategys(id); //策略的基本信息
  111. List<String> types = strategysBdMapper.getStrategysType(id);
  112. Iterator isTypeList = types.iterator();
  113. while (isTypeList.hasNext()) {
  114. String type = (String) isTypeList.next();
  115. if ("0".equals(type)) {
  116. userGroupNameList = strategysBdMapper.getUserGroupIdAndName(id);
  117. System.out.println("userG:" + userGroupNameList);
  118. } else {
  119. userNameList = strategysBdMapper.getUserIdAndName(id);
  120. System.out.println("user" + userNameList);
  121. }
  122. }
  123. strategysDatas.setStrategies(strategys);
  124. strategysDatas.setUserGroupName(userGroupNameList);
  125. strategysDatas.setUserName(userNameList);
  126. strategysDataList.add(strategysDatas);
  127. System.out.println("strate:" + strategysDataList);
  128. }
  129. return new RepEntity(RepCode.success, strategysDataList);
  130. }
  131. /*
  132. 添加用户或用户组
  133. */
  134. public RepEntity addObject(ObjectInfo objectInfo){
  135. String type = objectInfo.getType();
  136. int stId = objectInfo.getStId();
  137. if ("base".equals(type)){
  138. strategysBdMapper.delObject(stId);
  139. }else if ("chart".equals(type)){
  140. strategysChartMapper.delObject(stId);
  141. }else {
  142. dashboardsMapper.delObject(stId);
  143. }
  144. List objs = objectInfo.getObj();
  145. Iterator isObj = objs.iterator();
  146. while (isObj.hasNext()) {
  147. Obj obj = (Obj) isObj.next();
  148. String obType = obj.getObjectType();
  149. int obId = obj.getObId();
  150. System.out.println("obId:" + obId);
  151. if ("base".equals(type)) {
  152. strategysBdMapper.addObject(stId, obType, obId);
  153. } else if ("chart".equals(type)){
  154. strategysChartMapper.addObject(stId, obType, obId);
  155. }else {
  156. dashboardsMapper.addObject(stId, obType, obId);
  157. }
  158. }
  159. return new RepEntity(RepCode.success);
  160. }
  161. /*
  162. 查询图表策略列表
  163. */
  164. public RepEntity getChartStrategys(int chartId){
  165. System.out.println(",,,");
  166. List<StrategysData> strategysDataList = new ArrayList<>();
  167. /*
  168. 获取id列表
  169. */
  170. List<Integer> idList = strategysChartMapper.getStrIdList(chartId);
  171. Iterator isList = idList.iterator();
  172. while (isList.hasNext()) {
  173. int id = (int) isList.next();
  174. List<Map<String, Object>> userGroupNameList = new ArrayList<>();
  175. List<Map<String, Object>> userNameList = new ArrayList<>();
  176. StrategysData strategysDatas = new StrategysData();
  177. Strategys strategys = strategysChartMapper.getStrategys(id); //策略的基本信息
  178. List<String> types = strategysChartMapper.getStrategysType(id);
  179. Iterator isTypeList = types.iterator();
  180. while (isTypeList.hasNext()) {
  181. String type = (String) isTypeList.next();
  182. if ("0".equals(type)) {
  183. userGroupNameList = strategysChartMapper.getUserGroupIdAndName(id);
  184. } else {
  185. userNameList = strategysChartMapper.getUserIdAndName(id);
  186. }
  187. }
  188. strategysDatas.setStrategies(strategys);
  189. strategysDatas.setUserGroupName(userGroupNameList);
  190. strategysDatas.setUserName(userNameList);
  191. strategysDataList.add(strategysDatas);
  192. }
  193. return new RepEntity(RepCode.success, strategysDataList);
  194. }
  195. }