| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- package com.server;
- import com.dao.DashboardsMapper;
- import com.dao.StrategysBdMapper;
- import com.dao.StrategysChartMapper;
- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.model.bo.Obj;
- import com.model.po.Strategys;
- import com.model.po.StrategysData;
- import com.model.pojo.RepCode;
- import com.model.pojo.RepEntity;
- import com.model.vo.configVo.ObjectInfo;
- import com.model.vo.configVo.StrategysInfo;
- import com.util.ScreenUtil;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import java.util.*;
- @Service
- public class StrategysService {
- @Autowired
- ScreenUtil screenUtil;
- @Autowired
- StrategysBdMapper strategysBdMapper;
- @Autowired
- StrategysChartMapper strategysChartMapper;
- @Autowired
- ObjectMapper objectMapper;
- @Autowired
- DashboardsMapper dashboardsMapper;
- /*
- 保存数据源策略
- */
- public RepEntity addStrategys(StrategysInfo strategysInfo){
- Strategys strategys = new Strategys();
- BeanUtils.copyProperties(strategysInfo, strategys);
- String scr = screenUtil.screensUtil(strategysInfo.getRule(), "", "").getRet();
- strategys.setRule(scr);
- strategys.setRuleStr(String.valueOf(strategysInfo.getRule()));
- String type = strategysInfo.getType();
- if ("base".equals(type)){
- strategysBdMapper.addStrategys(strategys);
- }else {
- strategysChartMapper.addStrategys(strategys);
- }
- return new RepEntity(RepCode.success, strategys.getId());
- }
- /*
- 更新数据源策略
- */
- public RepEntity updateStrategys(StrategysInfo strategysInfo){
- Strategys strategys = new Strategys();
- BeanUtils.copyProperties(strategysInfo, strategys);
- String scr = screenUtil.screensUtil(strategysInfo.getRule(), "", "").getRet();
- strategys.setRule(scr);
- String ruleStr = null;
- try {
- ruleStr = objectMapper.writeValueAsString(strategysInfo.getRule());
- } catch (JsonProcessingException e) {
- e.printStackTrace();
- }
- strategys.setRuleStr(ruleStr);
- String type = strategysInfo.getType();
- if ("base".equals(type)) {
- strategysBdMapper.updataStrategys(strategys);
- }else {
- strategysChartMapper.updataStrategys(strategys);
- }
- return new RepEntity(RepCode.success);
- }
- /*
- 删除数据源策略
- */
- public RepEntity delDbStrategys(List<Integer> idList){
- strategysBdMapper.delStrategys(idList);
- Iterator isList = idList.iterator();
- while (isList.hasNext()){
- int id = (int) isList.next();
- strategysBdMapper.delObject(id);
- }
- return new RepEntity(RepCode.success);
- }
- /*
- 删除图表策略
- */
- public RepEntity delChartStrategys(List<Integer> idList){
- strategysChartMapper.delStrategys(idList);
- Iterator isList = idList.iterator();
- while (isList.hasNext()){
- int id = (int) isList.next();
- strategysChartMapper.delObject(id);
- }
- return new RepEntity(RepCode.success);
- }
- /*
- 查询数据源策略列表
- */
- public RepEntity getDbStrategys(int DbId){
- List<StrategysData> strategysDataList = new ArrayList<>();
- /*
- 获取id列表
- */
- List<Integer> idList = strategysBdMapper.getStrIdList(DbId);
- Iterator isList = idList.iterator();
- while (isList.hasNext()) {
- int id = (int) isList.next();
- List<Map<String, Object>> userGroupNameList = new ArrayList<>();
- List<Map<String, Object>> userNameList = new ArrayList<>();
- StrategysData strategysDatas = new StrategysData();
- Strategys strategys = strategysBdMapper.getStrategys(id); //策略的基本信息
- List<String> types = strategysBdMapper.getStrategysType(id);
- Iterator isTypeList = types.iterator();
- while (isTypeList.hasNext()) {
- String type = (String) isTypeList.next();
- if ("0".equals(type)) {
- userGroupNameList = strategysBdMapper.getUserGroupIdAndName(id);
- System.out.println("userG:" + userGroupNameList);
- } else {
- userNameList = strategysBdMapper.getUserIdAndName(id);
- System.out.println("user" + userNameList);
- }
- }
- strategysDatas.setStrategies(strategys);
- strategysDatas.setUserGroupName(userGroupNameList);
- strategysDatas.setUserName(userNameList);
- strategysDataList.add(strategysDatas);
- System.out.println("strate:" + strategysDataList);
- }
- return new RepEntity(RepCode.success, strategysDataList);
- }
- /*
- 添加用户或用户组
- */
- public RepEntity addObject(ObjectInfo objectInfo){
- String type = objectInfo.getType();
- int stId = objectInfo.getStId();
- if ("base".equals(type)){
- strategysBdMapper.delObject(stId);
- }else if ("chart".equals(type)){
- strategysChartMapper.delObject(stId);
- }else {
- dashboardsMapper.delObject(stId);
- }
- List objs = objectInfo.getObj();
- Iterator isObj = objs.iterator();
- while (isObj.hasNext()) {
- Obj obj = (Obj) isObj.next();
- String obType = obj.getObjectType();
- int obId = obj.getObId();
- System.out.println("obId:" + obId);
- if ("base".equals(type)) {
- strategysBdMapper.addObject(stId, obType, obId);
- } else if ("chart".equals(type)){
- strategysChartMapper.addObject(stId, obType, obId);
- }else {
- dashboardsMapper.addObject(stId, obType, obId);
- }
- }
- return new RepEntity(RepCode.success);
- }
- /*
- 查询图表策略列表
- */
- public RepEntity getChartStrategys(int chartId){
- System.out.println(",,,");
- List<StrategysData> strategysDataList = new ArrayList<>();
- /*
- 获取id列表
- */
- List<Integer> idList = strategysChartMapper.getStrIdList(chartId);
- Iterator isList = idList.iterator();
- while (isList.hasNext()) {
- int id = (int) isList.next();
- List<Map<String, Object>> userGroupNameList = new ArrayList<>();
- List<Map<String, Object>> userNameList = new ArrayList<>();
- StrategysData strategysDatas = new StrategysData();
- Strategys strategys = strategysChartMapper.getStrategys(id); //策略的基本信息
- List<String> types = strategysChartMapper.getStrategysType(id);
- Iterator isTypeList = types.iterator();
- while (isTypeList.hasNext()) {
- String type = (String) isTypeList.next();
- if ("0".equals(type)) {
- userGroupNameList = strategysChartMapper.getUserGroupIdAndName(id);
- } else {
- userNameList = strategysChartMapper.getUserIdAndName(id);
- }
- }
- strategysDatas.setStrategies(strategys);
- strategysDatas.setUserGroupName(userGroupNameList);
- strategysDatas.setUserName(userNameList);
- strategysDataList.add(strategysDatas);
- }
- return new RepEntity(RepCode.success, strategysDataList);
- }
- }
|