Jelajahi Sumber

Merge branch 'dev' of http://192.168.1.220:10080/jiwei/jw2.0 into dev

chenweida 7 tahun lalu
induk
melakukan
ac546025b4
25 mengubah file dengan 2212 tambahan dan 0 penghapusan
  1. 115 0
      base/common-data-fastdfs/src/main/java/com/yihu/ehr/config/FastDFSConfig.java
  2. 65 0
      base/common-data-fastdfs/src/main/java/com/yihu/ehr/fastdfs/FastDFSClientPool.java
  3. 299 0
      base/common-data-fastdfs/src/main/java/com/yihu/ehr/fastdfs/FastDFSUtil.java
  4. 88 0
      common/common-data-es/src/main/java/com/yihu/base/es/config/ElasticFactory.java
  5. 21 0
      common/common-data-es/src/main/java/com/yihu/base/es/config/model/SaveModel.java
  6. 133 0
      common/common-data-solr/src/main/java/com/yihu/base/SolrAdmin.java
  7. 31 0
      common/common-data-solr/src/main/java/com/yihu/base/SolrContext.java
  8. 52 0
      common/common-data-solr/src/main/java/com/yihu/base/SolrPool.java
  9. 416 0
      common/common-data-solr/src/main/java/com/yihu/base/SolrUtil.java
  10. 8 0
      common/common-swagger/src/main/java/com/yihu/jw/config.java
  11. 163 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/base/ModuleController.java
  12. 38 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/base/ModuleFunController.java
  13. 29 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/FunctionDao.java
  14. 28 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/ModuleDao.java
  15. 29 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/ModuleFunctionDao.java
  16. 20 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/SaasDao.java
  17. 16 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/SaasModuleDao.java
  18. 118 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/Function.java
  19. 97 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/Module.java
  20. 50 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/ModuleFunction.java
  21. 54 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/Saas.java
  22. 50 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/SaasModule.java
  23. 77 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/base/ModuleFunService.java
  24. 142 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/base/ModuleService.java
  25. 73 0
      svr/svr-base/src/main/java/com/yihu/jw/business/base/service/base/SaasService.java

+ 115 - 0
base/common-data-fastdfs/src/main/java/com/yihu/ehr/config/FastDFSConfig.java

@ -0,0 +1,115 @@
package com.yihu.ehr.config;
import com.yihu.ehr.fastdfs.FastDFSClientPool;
import com.yihu.ehr.fastdfs.FastDFSUtil;
import com.yihu.ehr.util.log.LogService;
import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.TrackerGroup;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
import java.net.InetSocketAddress;
/**
 * @author Sand
 * @version 1.0
 * @created 2015.11.27 16:08
 */
@Configuration
public class FastDFSConfig {
    @Value("${fast-dfs.pool.init-size}")
    private int initPoolSize;
    @Value("${fast-dfs.pool.max-size}")
    private int maxPoolSize;
    @Value("${fast-dfs.pool.wait-time}")
    private int waitTime;
    @Value("${fast-dfs.connect-timeout}")
    private int connectTimeout;
    @Value("${fast-dfs.network-timeout}")
    private int networkTimeout;
    @Value("${fast-dfs.charset}")
    private String charset;
    @Value("${fast-dfs.tracker-server}")
    private String trackerServers;
    @Value("${fast-dfs.http.tracker-http-port}")
    private int httpPort;
    @Value("${fast-dfs.http.anti-steal-token}")
    private boolean antiStealToken;
    @Value("${fast-dfs.http.secret-key}")
    private String secretKey;
    @PostConstruct
    void init() {
        try {
            // 此代码复制自:ClientGlobal.init() 方法
            ClientGlobal.g_connect_timeout = connectTimeout;
            if (ClientGlobal.g_connect_timeout < 0) {
                ClientGlobal.g_connect_timeout = 5;
            }
            ClientGlobal.g_connect_timeout *= 1000;
            ClientGlobal.g_network_timeout = networkTimeout;
            if (ClientGlobal.g_network_timeout < 0) {
                ClientGlobal.g_network_timeout = 30;
            }
            ClientGlobal.g_network_timeout *= 1000;
            ClientGlobal.g_charset = charset;
            if (ClientGlobal.g_charset == null || ClientGlobal.g_charset.length() == 0) {
                ClientGlobal.g_charset = "ISO8859-1";
            }
            String[] szTrackerServers = trackerServers.split(";");
            if (szTrackerServers == null) {
                throw new MyException("item \"tracker_server\" not found");
            } else {
                InetSocketAddress[] tracker_servers = new InetSocketAddress[szTrackerServers.length];
                for (int i = 0; i < szTrackerServers.length; ++i) {
                    String[] parts = szTrackerServers[i].split("\\:", 2);
                    if (parts.length != 2) {
                        throw new MyException("the value of item \"tracker_server\" is invalid, the correct format is host:port");
                    }
                    tracker_servers[i] = new InetSocketAddress(parts[0].trim(), Integer.parseInt(parts[1].trim()));
                }
                ClientGlobal.g_tracker_group = new TrackerGroup(tracker_servers);
                ClientGlobal.g_tracker_http_port = httpPort;
                ClientGlobal.g_anti_steal_token = antiStealToken;
                if (ClientGlobal.g_anti_steal_token) {
                    ClientGlobal.g_secret_key = secretKey;
                }
            }
        } catch (MyException e) {
            LogService.getLogger(FastDFSUtil.class).error("FastDFS初始化失败: " + e.getMessage());
        }
    }
    @Bean
    public FastDFSClientPool fastDFSClientPool(){
        FastDFSClientPool clientPool = new FastDFSClientPool();
        clientPool.setMaxPoolSize(maxPoolSize);
        return clientPool;
    }
    @Bean
    public FastDFSUtil fastDFSUtil(){
        FastDFSUtil util = new FastDFSUtil();
        return util;
    }
}

+ 65 - 0
base/common-data-fastdfs/src/main/java/com/yihu/ehr/fastdfs/FastDFSClientPool.java

@ -0,0 +1,65 @@
package com.yihu.ehr.fastdfs;
import org.csource.fastdfs.StorageClient;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
/**
 * Created by szx on 2015/9/19.
 */
public class FastDFSClientPool {
    private int maxPoolSize;
    private Map<StorageClient, Boolean> map = new HashMap<>();
    public void setMaxPoolSize(int poolSize){
        this.maxPoolSize = poolSize;
    }
    public TrackerServer getTrackerServer() throws IOException {
        TrackerClient tracker = new TrackerClient();
        return tracker.getConnection();
    }
    private StorageClient getNewStorageClient() throws IOException {
        TrackerClient tracker = new TrackerClient();
        TrackerServer trackerServer = tracker.getConnection();
        StorageClient client = new StorageClient(trackerServer, null);
        return client;
    }
    public synchronized StorageClient getStorageClient() throws IOException {
        StorageClient client = null;
        for (Entry<StorageClient, Boolean> entry : map.entrySet()) {
            if (entry.getValue()) {
                client = entry.getKey();
                map.put(client, false);
                break;
            }
        }
        if (client == null) {
            if (map.size() < maxPoolSize) {
                client = getNewStorageClient();
                map.put(client, false);
            }
        }
        return client;
    }
    public void releaseStorageClient(StorageClient client) {
        if (client == null) return;
        if (map.containsKey(client)) {
            map.put(client, true);
        } else {
            client = null;
        }
    }
}

+ 299 - 0
base/common-data-fastdfs/src/main/java/com/yihu/ehr/fastdfs/FastDFSUtil.java

@ -0,0 +1,299 @@
package com.yihu.ehr.fastdfs;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.ehr.util.log.LogService;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.InputStream;
import java.net.InetSocketAddress;
/**
 * FastDFS 客户端工具.
 *
 * 作为Bean方式来调用。
 *
 * @author szx
 * @author Sand
 */
public class FastDFSUtil {
    public final static String GroupField = "groupName";
    public final static String RemoteFileField = "remoteFileName";
    public final static String FileIdField = "fid";
    public final static String FileUrlField = "fileUrl";
    
    @Autowired
    FastDFSClientPool clientPool;
    /**
     * 以输入流的方式上传文件
     * InputStream in = new FileInputStream("C://Desert.jpg");
     * ObjectNode msg = FileUtil.upload(in,"jpg", "沙漠");
     * in.close();
     *
     * @param in            输入流
     * @param fileExtension 文件扩展名,不要带“.”
     * @param description   文件名称(中文)
     * @return 返回值的格式如下:
     * {
     * "groupName": "healthArchiveGroup",
     * "remoteFileName": "/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     * "fid": "group1/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     * "fileURL": "http://172.19.103.13/healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * }
     * <p>
     * groupName 及 remoteFileName 可以用于查询在 fastDFS 中文件的信息,如果只是图片显示,可以忽略这两个值。
     * fid 保存了在 fastDFS 上的完整路径,为了避免将来服务器域名发生变更,最好使用本值.服务器的域名另外配置。
     * fileURL 保存了完整的 web 访问路径,为了避免将来服务器域名发生变更,最好不要直接使用本值。
     * 如果需要在下载时,可以显示原始文件名,请在访问file_url时,增加 attname 参数,如:
     * <p>
     * http://host/healthArchiveGroup/M00/00/00/rBFuH1XdIseAUTZZAA1rIuRd3Es062.jpg?attname=a.jpg
     * @throws Exception
     */
    public ObjectNode upload(InputStream in, String fileExtension,String description) throws Exception {
        NameValuePair[] fileMetaData = new NameValuePair[1];
        fileMetaData[0] = new NameValuePair("description", description == null ? "" : description);
        return upload(in,fileExtension,fileMetaData);
    }
    /**
     * 以输入流的方式上传文件
     */
    public ObjectNode upload(InputStream in, String fileExtension,NameValuePair[] fileMetaData) throws Exception {
        StorageClient client = clientPool.getStorageClient();
        ObjectNode message = new ObjectMapper().createObjectNode();
        try {
            byte fileBuffer[] = new byte[in.available()];
            int len = 0;
            int temp = 0;                             //所有读取的内容都使用temp接收
            while ((temp = in.read()) != -1) {            //当没有读取完时,继续读取
                fileBuffer[len] = (byte) temp;
                len++;
            }
            in.close();
            TrackerServer trackerServer = clientPool.getTrackerServer();
            String[] results = client.upload_file(fileBuffer, fileExtension, fileMetaData);
            if (results != null) {
                String fileId;
                int ts;
                String token;
                String fileURl;
                InetSocketAddress socketAddress;
                String groupName = results[0];
                String remoteFile = results[1];
                message.put(GroupField, groupName);
                message.put(RemoteFileField, remoteFile);
                fileId = groupName + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remoteFile;
                message.put(FileIdField, fileId);
                socketAddress = trackerServer.getInetSocketAddress();
                fileURl = "http://" + socketAddress.getAddress().getHostAddress();
                if (ClientGlobal.g_tracker_http_port != 80) {
                    fileURl += ":" + ClientGlobal.g_tracker_http_port;
                }
                fileURl += "/" + fileId;
                if (ClientGlobal.g_anti_steal_token) {
                    ts = (int) (System.currentTimeMillis() / 1000);
                    token = ProtoCommon.getToken(fileId, ts, ClientGlobal.g_secret_key);
                    fileURl += "?token=" + token + "&ts=" + ts;
                }
                message.put(FileUrlField, fileURl);
                LogService.getLogger(FastDFSUtil.class).info(client.get_file_info(groupName, remoteFile).toString());
            }
        } finally {
            clientPool.releaseStorageClient(client);
        }
        return message;
    }
    /**
     * 上传文件,从文件
     */
    public ObjectNode upload(String group_name, String master_filename, String prefix_name, byte[] file_buff, String file_ext_name,NameValuePair[] meta_list) throws Exception{
        StorageClient client = clientPool.getStorageClient();
        ObjectNode message = new ObjectMapper().createObjectNode();
        try {
            TrackerServer trackerServer = clientPool.getTrackerServer();
            String[] results = client.upload_file(group_name,master_filename,prefix_name,file_buff, file_ext_name, meta_list);
            if (results != null) {
                String fileId;
                int ts;
                String token;
                String fileURl;
                InetSocketAddress socketAddress;
                String groupName = results[0];
                String remoteFile = results[1];
                message.put(GroupField, groupName);
                message.put(RemoteFileField, remoteFile);
                fileId = groupName + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remoteFile;
                message.put(FileIdField, fileId);
                socketAddress = trackerServer.getInetSocketAddress();
                fileURl = "http://" + socketAddress.getAddress().getHostAddress();
                if (ClientGlobal.g_tracker_http_port != 80) {
                    fileURl += ":" + ClientGlobal.g_tracker_http_port;
                }
                fileURl += "/" + fileId;
                if (ClientGlobal.g_anti_steal_token) {
                    ts = (int) (System.currentTimeMillis() / 1000);
                    token = ProtoCommon.getToken(fileId, ts, ClientGlobal.g_secret_key);
                    fileURl += "?token=" + token + "&ts=" + ts;
                }
                message.put(FileUrlField, fileURl);
                System.out.print(client.get_file_info(groupName, remoteFile).toString());
            }
        } finally {
            clientPool.releaseStorageClient(client);
        }
        return message;
    }
    /**
     * 上传本地文件
     * ObjectNode  a = FileUtil.upload("C://Desert.jpg", "沙漠");
     * System.out.println(a.toString());
     *
     * @param fileName    本地文件的绝对路径,如 C://Desert.jpg
     * @param description 文件备注, 可以为空
     * @return {"groupName":"group1","remoteFileName":"/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * {
     * "groupName": "healthArchiveGroup",
     * "remoteFileName": "/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     * "fid": "group1/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg",
     * "fileURL": "http://172.19.103.13/healthArchiveGroup/M00/00/24/rBFuH1XdQC6AP3CDAAzodQCbVVc052.jpg"
     * }
     * <p>
     * groupName 及 remoteFileName 可以用于查询在 fastDFS 中文件的信息,如果只是图片显示,可以忽略这两个值。
     * fid 保存了在 fastDFS 上的完整路径,为了避免将来服务器域名发生变更,最好使用本值.服务器的域名另外配置。
     * fileURL 保存了完整的 web 访问路径,为了避免将来服务器域名发生变更,最好不要直接使用本值。
     * 如果需要在下载时,可以显示原始文件名,请在访问file_url时,增加 attname 参数,如:
     * <p>
     * http://host/healthArchiveGroup/M00/00/00/rBFuH1XdIseAUTZZAA1rIuRd3Es062.jpg?attname=a.jpg
     * @throws Exception
     */
    public ObjectNode upload(String fileName, String description) throws Exception {
        StorageClient client = clientPool.getStorageClient();
        try {
            NameValuePair[] fileMetaData;
            fileMetaData = new NameValuePair[1];
            fileMetaData[0] = new NameValuePair("description", description == null ? "" : description);
//            ObjectMapper objectMapper = SpringContext.getService(ObjectMapper.class);
            ObjectNode message = new ObjectMapper().createObjectNode();
            String fileExtension = "";
            if (fileName.contains(".")) {
                fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
            } else {
                throw new RuntimeException("上传失败, 文件缺失扩展名.");
            }
            TrackerServer trackerServer = clientPool.getTrackerServer();
            String[] results = client.upload_file(fileName, fileExtension, fileMetaData);
            if (results != null) {
                String fileId;
                int ts;
                String token;
                String fileUrl;
                InetSocketAddress inetSockAddr;
                String groupName = results[0];
                String remoteFileName = results[1];
                message.put(GroupField, groupName);
                message.put(RemoteFileField, remoteFileName);
                fileId = groupName + StorageClient1.SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + remoteFileName;
                message.put(FileIdField, fileId);
                inetSockAddr = trackerServer.getInetSocketAddress();
                fileUrl = "http://" + inetSockAddr.getAddress().getHostAddress();
                if (ClientGlobal.g_tracker_http_port != 80) {
                    fileUrl += ":" + ClientGlobal.g_tracker_http_port;
                }
                fileUrl += "/" + fileId;
                if (ClientGlobal.g_anti_steal_token) {
                    ts = (int) (System.currentTimeMillis() / 1000);
                    token = ProtoCommon.getToken(fileId, ts, ClientGlobal.g_secret_key);
                    fileUrl += "?token=" + token + "&ts=" + ts;
                }
                message.put(FileUrlField, fileUrl);
                LogService.getLogger(FastDFSUtil.class).info(client.get_file_info(groupName, remoteFileName).toString());
                return message;
            } else {
                return null;
            }
        } finally {
            clientPool.releaseStorageClient(client);
        }
    }
    /**
     * 下载文件, 返回文件字节数组.
     *
     * @param groupName      在fastdfs上的卷名
     * @param remoteFileName 在fastdfs上的路径
     * @return 文件的字节码
     * @throws Exception
     */
    public byte[] download(String groupName, String remoteFileName) throws Exception {
        StorageClient client = clientPool.getStorageClient();
        try {
            byte[] b = client.download_file(groupName, remoteFileName);
            return b;
        } finally {
            clientPool.releaseStorageClient(client);
        }
    }
    /**
     * 下载文件到本地路径上.
     *
     * @param groupName      在 fastDFS 上的卷名
     * @param remoteFileName 在 fastDFS 上的路径
     * @param localPath      本地路径
     * @return 是否下载成功
     */
    public String download(String groupName, String remoteFileName, String localPath) throws Exception {
        StorageClient client = clientPool.getStorageClient();
        try {
            String localFileName = localPath + remoteFileName.replaceAll("/", "_");
            client.download_file(groupName, remoteFileName, 0, 0, localFileName);
            return localFileName;
        } finally {
            clientPool.releaseStorageClient(client);
        }
    }
    /**
     * 删除文件。
     *
     * @param groupName
     * @param remoteFileName
     */
    public void delete(String groupName, String remoteFileName) throws Exception {
        StorageClient client = clientPool.getStorageClient();
        try {
            client.delete_file(groupName, remoteFileName);
        } finally {
            clientPool.releaseStorageClient(client);
        }
    }
}

+ 88 - 0
common/common-data-es/src/main/java/com/yihu/base/es/config/ElasticFactory.java

@ -0,0 +1,88 @@
package com.yihu.jw.es.config;
import io.searchbox.client.JestClient;
import io.searchbox.client.JestClientFactory;
import io.searchbox.client.config.HttpClientConfig;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
/**
 * Created by chenweida on 2017/6/5.
 */
@Component
public class ElasticFactory {
    private static JestClientFactory factory = null;
    @Value("${es.host}")
    private String esHost;
    @Value("${es.port}")
    private String port;
    @Value("${es.tPort}")
    private String tPort;
    @Value("${es.clusterName}")
    private String clusterName;
//-----------------------------------jestClient----------------------------------------
    /**
     * @param "http://localhost:9200"
     * @return
     */
    public JestClient getJestClient() {
        if (factory == null) {
            //初始化链接
            init();
        }
        return factory.getObject();
    }
    /**
     * 初始化链接
     */
    public synchronized void init() {
        // Construct a new Jest client according to configuration via factory
        factory = new JestClientFactory();
        factory.setHttpClientConfig(new HttpClientConfig
                .Builder("http://" + esHost + ":" + port)
                .multiThreaded(true)
                .maxTotalConnection(50)// 最大链接
                .maxConnectionIdleTime(120, TimeUnit.SECONDS)//链接等待时间
                .connTimeout(60*1000)
               // .discoveryEnabled(true)
                .readTimeout(60*1000)//60秒
                .build());//得到链接
    }
    //-----------------------------------TransportClient----------------------------------------
    private Client transportClient;
    public Client getTransportClient() {
        try {
            initTranClient();
            return transportClient;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    private synchronized void initTranClient() throws UnknownHostException {
        if (transportClient == null) {
            Settings settings = Settings.settingsBuilder()
                   // .put("client.transport.sniff", true)//开启嗅探功能
                    .put("cluster.name", StringUtils.isEmpty(clusterName) ? "jkzl" : clusterName)//默认集群名字是jkzl
                    .build();
            transportClient = TransportClient.builder().settings(settings).build()
                    .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(esHost), Integer.valueOf(tPort)));
        }
    }
}

+ 21 - 0
common/common-data-es/src/main/java/com/yihu/base/es/config/model/SaveModel.java

@ -0,0 +1,21 @@
package com.yihu.jw.es.config.model;
import io.searchbox.annotations.JestId;
/**
 * es保存model的公共父类
 * Created by chenweida on 2017/11/3.
 */
public class SaveModel {
    @JestId
    private String id;
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
}

+ 133 - 0
common/common-data-solr/src/main/java/com/yihu/base/SolrAdmin.java

@ -0,0 +1,133 @@
package com.yihu.base;
import org.apache.commons.collections.map.HashedMap;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * Solr底层操作类
 *
 * @author hzp
 * @version 1.0
 * @created 2017.05.06
 */
@Service
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SolrAdmin {
    @Autowired
    SolrPool pool;
    /************************* 基础操作 **************************************************/
    /**
     * 新建单条索引
     */
    public Boolean create(String core,Map<String, Object> map) throws Exception {
        SolrClient client = pool.getConnection(core);
        SolrInputDocument doc = new SolrInputDocument();
        //注意date的格式,要进行适当的转化
        for(String key:map.keySet())
        {
            doc.addField(key, map.get(key));
        }
        UpdateResponse re = client.add(doc);
        client.commit();
        pool.close(core); //释放连接
        if(re.getStatus()!=0) {
            System.out.print("create index cost " + re.getQTime());
            return true;
        }
        else{
            System.out.print("create index faild!");
            return false;
        }
    }
    /**
     * 修改单条索引单字段
     */
    public Boolean update(String core,String uniqueKey,String uniqueKeyValue,String key,Object value) throws Exception {
        Map<String,Object> map = new HashedMap();
        map.put(key,value);
        return update(core,uniqueKey+":"+uniqueKeyValue,map);
    }
    /**
     * 修改索引多字段
     */
    public Boolean update(String core,String keyQuery,Map<String, Object> map) throws Exception {
        SolrClient client = pool.getConnection(core);
        QueryResponse qr = client.query(new SolrQuery(keyQuery));
        SolrDocumentList docs = qr.getResults();
        if(docs!=null && docs.size()>0)
        {
            List<SolrInputDocument> solrList = new ArrayList<>();
            for(int i=0;i<docs.size();i++)
            {
                SolrDocument doc = docs.get(i);
                SolrInputDocument newItem = new SolrInputDocument();
                newItem.addField("rowkey",doc.get("rowkey"));
                for(String key :map.keySet())
                {
                    newItem.addField(key,map.get(key));
                }
                solrList.add(newItem);
            }
            UpdateResponse re = client.add(solrList);
            client.commit();
            pool.close(core); //释放连接
            if(re.getStatus()!=0) {
                System.out.print("update index cost " + re.getQTime());
                return true;
            }
            else{
                System.out.print("update index faild!");
                return false;
            }
        }
        else{
            System.out.print("Null result!");
        }
        return true;
    }
    /**
     * 删除单条索引
     */
    public Boolean delete(String core,String keyQuery) throws Exception {
        SolrClient client = pool.getConnection(core);
        UpdateResponse de = client.deleteByQuery(keyQuery);
        client.commit();
        pool.close(core); //释放连接
        if(de.getStatus()!=0) {
            System.out.print("delete index cost " + de.getQTime());
            return true;
        }
        else{
            System.out.print("delete index faild!");
            return false;
        }
    }
}

+ 31 - 0
common/common-data-solr/src/main/java/com/yihu/base/SolrContext.java

@ -0,0 +1,31 @@
package com.yihu.base;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.solr.core.SolrTemplate;
/**
 * Solr配置。仅支持SolrCloud,不支持单核模式。
 *
 * @author Sand
 * @version 1.0
 * @created 2016.04.18 18:47
 */
@Configuration
public class SolrContext {
    @Value("${spring.data.solr.zk-host}")
    String zkHost;
    @Bean
    public SolrClient solrClient() {
        return new CloudSolrClient(zkHost);
    }
    @Bean
    public SolrTemplate solrTemplate(SolrClient solrClient) throws Exception {
        return new SolrTemplate(solrClient);
    }
}

+ 52 - 0
common/common-data-solr/src/main/java/com/yihu/base/SolrPool.java

@ -0,0 +1,52 @@
package com.yihu.base;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.solr.server.support.MulticoreSolrClientFactory;
import org.springframework.stereotype.Service;
/**
 * Solr连接池
 * @author hzp
 * @version 1.0
 * @created 2016.04.26
 */
@Service
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class SolrPool {
    @Value("${spring.data.solr.zk-host}")
    String zkHost;
    private MulticoreSolrClientFactory factory;
    protected MulticoreSolrClientFactory getFactory(){
        if(factory==null)
        {
            CloudSolrClient client = new CloudSolrClient(zkHost);
            factory = new MulticoreSolrClientFactory(client);
        }
        return factory;
    }
    /**
     * 获取连接
     */
    public SolrClient getConnection(String core) throws Exception{
        return getFactory().getSolrClient(core);
    }
    /**
     * 关闭连接
     */
    public void close(String core) throws Exception{
        getFactory().removeSolrClient(core);
    }
}

+ 416 - 0
common/common-data-solr/src/main/java/com/yihu/base/SolrUtil.java

@ -0,0 +1,416 @@
eeepackage com.yihu.base;
import org.apache.commons.lang3.StringUtils;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.response.*;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.FacetParams;
import org.apache.solr.common.util.NamedList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Solr底层查询类
 *
 * @author hzp
 * @version 1.0
 * @created 2016.04.26
 */
@Service
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public class SolrUtil {
    @Autowired
    SolrPool pool;
    private final static String ASC = "asc";
    /**
     * 获取查询耗时
     */
    private int qtime;
    private int getQtime() {
        return qtime;
    }
    /************************** 查询操作 *****************************************************/
    /**
     * 简单查询方法
     */
    public SolrDocumentList query(String tablename, String q, Map<String, String> sort, long start, long rows) throws Exception {
        return query(tablename, q, null, sort, start, rows);
    }
    /**
     * Solr查询方法
     *
     * @param q     查询字符串
     * @param fq    过滤查询
     * @param sort  过滤条件
     * @param start 查询起始行
     * @param rows  查询行数
     * @return
     */
    public SolrDocumentList query(String core, String q, String fq, Map<String, String> sort, long start, long rows) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        if (null != q && !q.equals("")) //设置查询条件
        {
            query.setQuery(q);
        } else {
            query.setQuery("*:*");
        }
        if (null != fq && !fq.equals("")) //设置过滤条件
        {
            query.setFilterQueries(fq);
        }
        query.setStart(Integer.parseInt(String.valueOf(start)));//设置查询起始行
        query.setRows(Integer.parseInt(String.valueOf(rows)));//设置查询行数
        //设置排序
        if (sort != null) {
            for (Object co : sort.keySet()) {
                if (ASC == sort.get(co).toLowerCase() || ASC.equals(sort.get(co).toLowerCase())) {
                    query.addSort(co.toString(), SolrQuery.ORDER.asc);
                } else {
                    query.addSort(co.toString(), SolrQuery.ORDER.desc);
                }
            }
        }
        QueryResponse rsp = conn.query(query);
        qtime = rsp.getQTime();
        System.out.print("Solr Query Time:" + qtime);
        SolrDocumentList docs = rsp.getResults();
        pool.close(core); //释放连接
        return docs;
    }
    /******************************* Count 统计 ***********************************************/
    /**
     * 总数查询方法
     */
    public long count(String core, String q) throws Exception {
        return count(core, q, null);
    }
    /**
     * 总数查询方法
     */
    public long count(String core, String q, String fq) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        if (null != q && !q.equals("")) //设置查询条件
        {
            query.setQuery(q);
        } else {
            query.setQuery("*:*");
        }
        if (null != fq && !fq.equals("")) //设置过滤条件
        {
            query.setFilterQueries(fq);
        }
        query.setStart(0);
        query.setRows(0);
        QueryResponse rsp = conn.query(query);
        Integer start =  (int)rsp.getResults().getNumFound();
        query.setStart(start);
        rsp = conn.query(query);
        qtime = rsp.getQTime();
        System.out.print("Solr Count Time:" + qtime);
        SolrDocumentList docs = rsp.getResults();
        pool.close(core);
        return docs.getNumFound();
    }
    /**
     * 单组分组Count统计(start从0开始)
     */
    public Map<String, Long> groupCount(String core, String q, String fq, String groupField, int start, int rows) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        if (null != q && !q.equals("")) //设置查询条件
        {
            query.setQuery(q);
        } else {
            query.setQuery("*:*");
        }
        if (null != fq && !fq.equals("")) //设置过滤条件
        {
            query.setFilterQueries(fq);
        }
        query.setFacet(true);//设置facet=on
        query.setRows(0);
        query.addFacetField(groupField);
        query.setFacetLimit(rows);//限制每次返回结果数
        query.set(FacetParams.FACET_OFFSET, start);
        query.setFacetMissing(false);//不统计null的值
        query.setFacetMinCount(0);// 设置返回的数据中每个分组的数据最小值,比如设置为0,则统计数量最小为0,不然不显示
        QueryResponse rsp = conn.query(query);
        List<FacetField.Count> countList = rsp.getFacetField(groupField).getValues();
        qtime = rsp.getQTime();
        System.out.print("Solr Group Time:" + qtime);
        Map<String, Long> rmap = new HashMap<String, Long>();
        for (FacetField.Count count : countList) {
            if (count.getCount() > 0)
                rmap.put(count.getName(), (long) count.getCount());
        }
        pool.close(core);
        return rmap;
    }
    /**
     * 多组分组Count(独立计算)
     */
    public List<FacetField> groupCount(String core, String q, String fq, String[] groups) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        if (null != q && !q.equals("")) //设置查询条件
        {
            query.setQuery(q);
        } else {
            query.setQuery("*:*");
        }
        if (null != fq && !fq.equals("")) //设置过滤条件
        {
            query.setFilterQueries(fq);
        }
        query.setFacet(true);//设置facet=on
        query.setRows(0);
        query.addFacetField(groups);
        query.setFacetLimit(1000);//限制每次返回结果数
        query.set(FacetParams.FACET_OFFSET, 0);
        query.setFacetMissing(true);//不统计null的值
        query.setFacetMinCount(0);// 设置返回的数据中每个分组的数据最小值,比如设置为0,则统计数量最小为0,不然不显示
        QueryResponse rsp = conn.query(query);
        qtime = rsp.getQTime();
        System.out.print("Solr Group Time:" + qtime);
        List<FacetField> facets = rsp.getFacetFields();
        pool.close(core);
        return facets;
    }
    /**
     * 多组分组Count统计(关联计算)
     *
     * @return
     */
    public List<PivotField> groupCountMult(String core, String q, String fq, String groupFields, int start, int rows) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        if (null != q && !q.equals("")) //设置查询条件
        {
            query.setQuery(q);
        } else {
            query.setQuery("*:*");
        }
        if (null != fq && !fq.equals("")) //设置过滤条件
        {
            query.setFilterQueries(fq);
        }
        query.setFacet(true);//设置facet=on
        query.setRows(0);
        query.addFacetPivotField(groupFields);
        query.setFacetLimit(rows);//限制每次返回结果数
        query.setFacetMissing(false);//不统计null的值
        query.setFacetMinCount(0);// 设置返回的数据中每个分组的数据最小值,比如设置为0,则统计数量最小为0,不然不显示
        QueryResponse rsp = conn.query(query);
        qtime = rsp.getQTime();
        System.out.print("Solr Group Time:" + qtime);
        NamedList<List<PivotField>> namedList = rsp.getFacetPivot();
        pool.close(core);
        if (namedList != null && namedList.size() > 0) {
            return namedList.getVal(0);
        } else
            return null;
    }
    /**************************** 数值统计 ******************************************/
    /**
     * 分组数值统计
     *
     * @param core       表名
     * @param q          查询条件
     * @param statsField 统计字段
     * @param groupField 分组字段
     * @return
     */
    public List<FieldStatsInfo> getStats(String core, String q, String fq, String statsField, String groupField) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        if (null != q && !q.equals("")) //设置查询条件
        {
            query.setQuery(q);
        } else {
            query.setQuery("*:*");
        }
        if (null != fq && !fq.equals("")) //设置过滤条件
        {
            query.setFilterQueries(fq);
        }
        query.addGetFieldStatistics(statsField);
        query.addStatsFieldFacets(statsField, groupField);
        query.setRows(0);
        QueryResponse rsp = conn.query(query);
        qtime = rsp.getQTime();
        System.out.print("Solr Stats Time:" + qtime);
        Map<String, FieldStatsInfo> stats = rsp.getFieldStatsInfo();
        pool.close(core);
        if (stats != null && stats.size() > 0) {
            Map<String, List<FieldStatsInfo>> map = stats.get(statsField).getFacets();
            if (map != null) {
                return map.get(groupField);
            }
        }
        return null;
    }
    /**
     * 查询统计
     *
     * @param core       表名
     * @param facetQuery 查询条件
     * @return
     * @throws Exception
     */
    public Map<String, Integer> getFacetQuery(String core, String facetQuery) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        query.setFacet(true);
        query.addFacetQuery(facetQuery);
        QueryResponse resp = conn.query(query);
        return resp.getFacetQuery();
    }
    /**
     * 单字段分组统计
     *
     * @param core
     * @param facetField
     * @param fq
     * @param minCount
     * @param start
     * @param limit
     * @param missing
     * @return
     * @throws Exception
     */
    public FacetField getFacetField(String core, String facetField, String fq, int minCount, int start, int limit, boolean missing) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        if (!StringUtils.isBlank(fq)) {
            query.setFilterQueries(fq);
        }
        query.setStart(start)
                .setRows(0)
                .setFacet(true)
                .addFacetField(facetField)
                .setFacetMinCount(minCount)
                .setFacetLimit(limit)
                .setFacetMissing(missing);
        QueryResponse resp = conn.query(query);
        return resp.getFacetField(facetField);
    }
    /**
     * 日期范围分组统计
     *
     * @param core
     * @param dateField
     * @param startTime
     * @param endTime
     * @param grap
     * @param fq
     * @return
     * @throws Exception
     */
    public List<RangeFacet> getFacetDateRange(String core, String dateField, Date startTime, Date endTime, String grap, String fq) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        if (!StringUtils.isBlank(fq)) {
            query.setFilterQueries(fq);
        }
        query.setRows(0)
               .setFacet(true)
               .addDateRangeFacet(dateField, startTime, endTime, grap);
        QueryResponse resp = conn.query(query);
        return resp.getFacetRanges();
    }
    /**
     * 数值型字段范围统计
     *
     * @param core
     * @param numField
     * @param start
     * @param end
     * @param grap
     * @param fq
     * @return
     * @throws Exception
     */
    public List<RangeFacet> getFacetNumRange(String core, String numField, int start, int end, int grap, String fq) throws Exception {
        SolrClient conn = pool.getConnection(core);
        SolrQuery query = new SolrQuery();
        query.setQuery("*:*");
        if (!StringUtils.isBlank(fq)) {
            query.setFilterQueries(fq);
        }
        query.setRows(0)
                .setFacet(true)
                .addNumericRangeFacet(numField, start, end, grap);
        QueryResponse resp = conn.query(query);
        return resp.getFacetRanges();
    }
}

+ 8 - 0
common/common-swagger/src/main/java/com/yihu/jw/config.java

@ -0,0 +1,8 @@
package com.yihu.jw;
/**
 * Created by chenweida on 2017/11/3.
 */
public class config
{
}

+ 163 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/base/ModuleController.java

@ -0,0 +1,163 @@
package com.yihu.jw.business.base.controller.base;
import com.yihu.jw.business.base.model.base.Module;
import com.yihu.jw.business.base.service.base.ModuleService;
import com.yihu.jw.restmodel.base.base.MModule;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.restmodel.exception.ApiException;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
/**
 * Created by chenweida on 2017/5/19.
 */
@RestController
@RequestMapping(BaseRequestMapping.api_common)
@Api(value = "模块模块", description = "模块接口管理")
public class ModuleController extends EnvelopRestController {
    @Autowired
    private ModuleService moduleService;
    @PostMapping(value = BaseRequestMapping.Module.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建模块", notes = "创建单个模块")
    public Envelop createModule(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) {
        try {
            Module module = toEntity(jsonData, Module.class);
            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_create, moduleService.createModule(module));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PutMapping(value = BaseRequestMapping.Module.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改模块", notes = "修改模块")
    public Envelop updateModule(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) {
        try {
            Module module = toEntity(jsonData, Module.class);
            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_update, moduleService.updateModule(module));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @DeleteMapping(value = BaseRequestMapping.Module.api_delete)
    @ApiOperation(value = "删除模块", notes = "删除模块")
    public Envelop deleteModule(
            @ApiParam(name = "codes", value = "codes")
            @PathVariable(value = "codes", required = true) String codes) {
        try {
            moduleService.deleteModule(codes);
            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_delete );
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @GetMapping(value = BaseRequestMapping.Module.api_getByCode)
    @ApiOperation(value = "根据code查找模块", notes = "根据code查找模块")
    public Envelop findByCode(
            @ApiParam(name = "code", value = "code")
            @PathVariable(value = "code", required = true) String code
    ) {
        try {
            return Envelop.getSuccess(BaseRequestMapping.Module.message_success_find, moduleService.findByCode(code));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @RequestMapping(value = BaseRequestMapping.Module.api_getList, method = RequestMethod.GET)
    @ApiOperation(value = "获取父模块列表(分页)")
    public Envelop getModules(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            //code like 1,name大于aa ,code 等于1 , defaultValue = "code?1;name>aa;code=1"
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        if(StringUtils.isBlank(sorts)){
            sorts = "-updateTime";
        }
        if(StringUtils.isBlank(filters)){
            filters = "parentCode=0;";
        }else{
            filters="parentCode=0;"+filters;
        }
        //得到list数据
        List<Module> list = moduleService.search(fields, filters, sorts, page, size);
        if(list!=null){
            for(Module module:list){//循环遍历,设置是否有子节点
                List<Module> children = moduleService.getChildren(module.getCode());
                //children长度为0时    state  “open”表示是子节点,“closed”表示为父节点;
                // children长度>0时,  state   “open,closed”表示是节点的打开关闭
                if (children.size()>0){
                    module.setState("closed");
                }else{
                    module.setState("open");
                }
            }
        }
        //获取总数
        long count=moduleService.getCount(filters);
        //封装头信息
        pagedResponse(request, response, count, page, size);
        //封装返回格式
        List<MModule> mModules = convertToModels(list, new ArrayList<>(list.size()), MModule.class, fields);
        return Envelop.getSuccessListWithPage(BaseRequestMapping.Module.message_success_find_Modules,mModules, page, size,count);
    }
    @GetMapping(value = BaseRequestMapping.Module.api_getListNoPage)
    @ApiOperation(value = "获取模块列表,不分页")
    public Envelop getListNoPage(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "code,name,saasId,parentCode,remark")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+name,+createTime")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        //得到list数据
        List<Module> list = moduleService.search(fields,filters,sorts);
        //封装返回格式
        List<MModule> mModules = convertToModels(list, new ArrayList<>(list.size()), MModule.class, fields);
        return Envelop.getSuccessList(BaseRequestMapping.Module.message_success_find_Modules,mModules);
    }
    @GetMapping(value =BaseRequestMapping.Module.api_getChildren )
    @ApiOperation(value="查找子节点")
    public Envelop getChildren(@PathVariable String code){
        List<Module> children = moduleService.getChildren(code);
        return Envelop.getSuccess("查询成功",children);
    }
}

+ 38 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/controller/base/ModuleFunController.java

@ -0,0 +1,38 @@
package com.yihu.jw.business.base.controller.base;
import com.yihu.jw.business.base.service.base.ModuleFunService;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * Created by chenweida on 2017/5/19.
 */
@RestController
@RequestMapping(BaseRequestMapping.api_common)
@Api(value = "模块功能模块", description = "模块功能模块")
public class ModuleFunController extends EnvelopRestController {
    @Autowired
    private ModuleFunService moduleFunService;
    @GetMapping(value = BaseRequestMapping.ModuleFun.api_getExistFun)
    @ApiOperation(value="查找已存在的功能")
    public Envelop getExistFunc(@PathVariable String code){
        List<String> funcs = moduleFunService.getExistFun(code);
        return Envelop.getSuccess("查询成功",funcs);
    }
    @PutMapping(value =  BaseRequestMapping.ModuleFun.api_changeFun,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "模块更新功能")
    public Envelop changeFun (@RequestBody String jsonData) {
        moduleFunService.changeFun(jsonData);
        return Envelop.getSuccess("更新成功",null);
    }
}

+ 29 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/FunctionDao.java

@ -0,0 +1,29 @@
package com.yihu.jw.business.base.dao.base;
import com.yihu.jw.business.base.model.base.Function;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by chenweida on 2017/5/19.
 */
public interface FunctionDao extends PagingAndSortingRepository<Function, Long>, JpaSpecificationExecutor<Function> {
    @Query("from Function f where f.name=?1 and f.status=1")
    Function findByName(String name);
    @Query("from Function f where f.name=?1 and f.status=1 and f.code != ?2")
    Function findByNameExcludeCode(String name, String code);
    @Query("from Function f where f.code=?1 and f.status=1")
    Function findByCode(String code);
    @Query("from Function f where f.parentCode=?1 and f.status=1")
    List<Function> getChildren(String code);
    @Query("from Function f where f.status=1")
    List<Function> findAll();
}

+ 28 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/ModuleDao.java

@ -0,0 +1,28 @@
package com.yihu.jw.business.base.dao.base;
import com.yihu.jw.business.base.model.base.Module;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by chenweida on 2017/5/19.
 */
public interface ModuleDao extends PagingAndSortingRepository<Module, Long>, JpaSpecificationExecutor<Module> {
    @Query("from Module f where f.name=?1 and f.status=1")
    Module findByName(String name);
    @Query("from Module f where f.name=?1 and f.status=1 and f.code != ?2")
    Module findByNameExcludeCode(String name, String code);
    @Query("from Module f where f.code=?1 and f.status=1")
    Module findByCode(String code);
    @Query("from Module f where f.parentCode=?1 and f.status=1")
    List<Module> getChildren(String code);
    @Query("from Module f where f.status=1")
    List<Module> findAll();
}

+ 29 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/ModuleFunctionDao.java

@ -0,0 +1,29 @@
package com.yihu.jw.business.base.dao.base;
import com.yihu.jw.business.base.model.base.ModuleFunction;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
/**
 * Created by chenweida on 2017/5/22.
 */
public interface ModuleFunctionDao extends PagingAndSortingRepository<ModuleFunction, Long>, JpaSpecificationExecutor<ModuleFunction> {
    @Transactional
    @Modifying
    @Query("delete from ModuleFunction es where es.moduleId = ?1")
    int deleteByModuleCode(String moduleCode);
    @Query("from ModuleFunction mf where mf.moduleId = ?1")
    List<ModuleFunction> findByModuleCode(String code);
    @Transactional
    @Modifying
    @Query("delete from ModuleFunction es where es.functionId = ?1 and es.moduleId = ?2")
    void delete(String delCode, String moduleCode);
}

+ 20 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/SaasDao.java

@ -0,0 +1,20 @@
package com.yihu.jw.business.base.dao.base;
import com.yihu.jw.business.base.model.base.Saas;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by chenweida on 2017/5/19.
 */
public interface SaasDao extends PagingAndSortingRepository<Saas, Long>, JpaSpecificationExecutor<Saas> {
    @Query("from Saas f where f.name=?1 and f.status=1")
    Saas findByName(String name);
    @Query("from Saas f where f.name=?1 and f.status=1 and f.code != ?2")
    Saas findByNameExcludeCode(String name, String code);
    @Query("from Saas f where f.code=?1 and f.status=1")
    Saas findByCode(String code);
}

+ 16 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/dao/base/SaasModuleDao.java

@ -0,0 +1,16 @@
package com.yihu.jw.business.base.dao.base;
import com.yihu.jw.business.base.model.base.SaasModule;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by chenweida on 2017/5/22.
 */
public interface SaasModuleDao extends PagingAndSortingRepository<SaasModule, Long>, JpaSpecificationExecutor<SaasModule> {
    @Modifying
    @Query("delete from SaasModule es where es.saasId = ?1")
    int deleteBySaasCode(String saasCode);
}

+ 118 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/Function.java

@ -0,0 +1,118 @@
package com.yihu.jw.business.base.model.base;// default package
import com.yihu.jw.business.base.model.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;
/**
 * WlyyFunction entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "base_function")
public class Function extends IdEntity implements java.io.Serializable {
	// Fields
	private String name; //功能名称
	private String saasId; // saasid
	private String parentCode; //父功能code
	private Integer status; //状态 -1 删除 0 禁用 可用
	private String url;//功能对应的后台url路径
	private String remark; //备注
	@Transient
	private List<Function> children = new ArrayList<>();
	@Transient
	private String text;//用于jstree显示
	// Constructors
	/** default constructor */
	public Function() {
	}
	public void setId(Long id) {
		this.id = id;
	}
	@Column(name = "code", length = 100)
	public String getCode() {
		return this.code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	@Column(name = "name", length = 200)
	public String getName() {
		return this.name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name = "saas_id", length = 100)
	public String getSaasId() {
		return this.saasId;
	}
	public void setSaasId(String saasId) {
		this.saasId = saasId;
	}
	@Column(name = "parent_code", length = 100)
	public String getParentCode() {
		return this.parentCode;
	}
	public void setParentCode(String parentCode) {
		this.parentCode = parentCode;
	}
	@Column(name = "status", precision = 2, scale = 0)
	public Integer getStatus() {
		return this.status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	@Column(name = "remark", length = 1000)
	public String getRemark() {
		return this.remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	public List<Function> getChildren() {
		return children;
	}
	public void setChildren(List<Function> children) {
		this.children = children;
	}
	public String getText() {
		return name;
	}
	public void setText(String text) {
		this.text = text;
	}
}

+ 97 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/Module.java

@ -0,0 +1,97 @@
package com.yihu.jw.business.base.model.base;// default package
import com.yihu.jw.business.base.model.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.util.ArrayList;
import java.util.List;
/**
 * WlyyModule entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "base_module")
public class Module extends IdEntity implements java.io.Serializable {
	// Fields
	private String name; //模块名称
	private String saasId; //关联 Saas code
	private String parentCode;//父id
	private Integer status; //-1 删除 0 禁用 可用
	private String remark;
	@Transient
	private String state ;   //closed:表示有子节点   open:表示没有子节点
	@Transient
	private List<Module> children = new ArrayList<>();
	// Constructors
	/** default constructor */
	public Module() {
	}
	@Column(name = "name", length = 200)
	public String getName() {
		return this.name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name = "saas_id", length = 100)
	public String getSaasId() {
		return this.saasId;
	}
	public void setSaasId(String saasId) {
		this.saasId = saasId;
	}
	@Column(name = "parent_code", length = 100)
	public String getParentCode() {
		return this.parentCode;
	}
	public void setParentCode(String parentCode) {
		this.parentCode = parentCode;
	}
	@Column(name = "status", precision = 2, scale = 0)
	public Integer getStatus() {
		return this.status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	@Column(name = "remark", length = 1000)
	public String getRemark() {
		return this.remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public List<Module> getChildren() {
		return children;
	}
	public void setChildren(List<Module> children) {
		this.children = children;
	}
}

+ 50 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/ModuleFunction.java

@ -0,0 +1,50 @@
package com.yihu.jw.business.base.model.base;// default package
import javax.persistence.*;
/**
 * WlyyModuleFunction entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "base_module_function")
public class ModuleFunction implements java.io.Serializable {
	// Fields
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	private String functionId;//关联 base_function    code
	private String moduleId;//关联 base_module  code
	// Constructors
	/** default constructor */
	public ModuleFunction() {
	}
	@Column(name = "function_id", length = 100)
	public String getFunctionId() {
		return this.functionId;
	}
	public void setFunctionId(String functionId) {
		this.functionId = functionId;
	}
	@Column(name = "module_id", length = 100)
	public String getModuleId() {
		return this.moduleId;
	}
	public void setModuleId(String moduleId) {
		this.moduleId = moduleId;
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
}

+ 54 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/Saas.java

@ -0,0 +1,54 @@
package com.yihu.jw.business.base.model.base;// default package
import com.yihu.jw.business.base.model.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
 * WlyySaas entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "base_saas")
public class Saas extends IdEntity implements java.io.Serializable {
	// Fields
	private String name;//名称
	private Integer status;//状态 -1 已删除 0待审核 1审核通过 2 审核不通过
	private String remark;//备注
	// Constructors
	/** default constructor */
	public Saas() {
	}
	@Column(name = "name", length = 200)
	public String getName() {
		return this.name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@Column(name = "status", precision = 2, scale = 0)
	public Integer getStatus() {
		return this.status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	@Column(name = "remark", length = 1000)
	public String getRemark() {
		return this.remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
}

+ 50 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/model/base/SaasModule.java

@ -0,0 +1,50 @@
package com.yihu.jw.business.base.model.base;// default package
import com.yihu.jw.business.base.model.IdEntity;
import javax.persistence.*;
/**
 * WlyySaasModule entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "base_saas_module")
public class SaasModule extends IdEntity implements java.io.Serializable {
	// Fields
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	private String saasId; //关联WlyySaas code
	private String moduleId; //关联 WlyyModule code
	// Constructors
	@Column(name = "saas_id", length = 100)
	public String getSaasId() {
		return this.saasId;
	}
	public void setSaasId(String saasId) {
		this.saasId = saasId;
	}
	@Column(name = "module_id", length = 100)
	public String getModuleId() {
		return this.moduleId;
	}
	public void setModuleId(String moduleId) {
		this.moduleId = moduleId;
	}
	@Override
	public Long getId() {
		return id;
	}
	@Override
	public void setId(Long id) {
		this.id = id;
	}
}

+ 77 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/base/ModuleFunService.java

@ -0,0 +1,77 @@
package com.yihu.jw.business.base.service.base;
import com.yihu.jw.business.base.dao.base.ModuleFunctionDao;
import com.yihu.jw.business.base.model.base.ModuleFunction;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.restmodel.exception.ApiException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
 * Created by chenweida on 2017/5/19.
 */
@Service
public class ModuleFunService extends BaseJpaService<ModuleFunction, ModuleFunctionDao> {
    @Autowired
    private ModuleFunctionDao moduleFunctionDao;
    /**
     * 根据模块code,获取已存在的功能code
     * @param code
     * @return
     */
    public List<String> getExistFun(String code) {
        List<ModuleFunction> moduleFuns = moduleFunctionDao.findByModuleCode(code);
        List<String> list = new ArrayList<>();
        for(ModuleFunction moduleFun:moduleFuns){
            list.add(moduleFun.getFunctionId());
        }
        return list;
    }
    /**
     * 更改模块关联的功能
     * @param jsonData
     */
    public void changeFun(String jsonData) {
        JSONObject jsonObject =  new JSONObject(jsonData);
        if(!jsonObject.has("moduleCode")){
            throw new ApiException(BaseContants.ModuleFun.moduleCode_is_null, CommonContants.common_error_params_code);
            //filterStr+="saasId="+jsonObject.get("saasId")+";";
        }
        if(!jsonObject.has("funCodes")){
            throw new ApiException(BaseContants.ModuleFun.funCodes_is_null, CommonContants.common_error_params_code);
        }
        String moduleCode = jsonObject.get("moduleCode").toString();//模块code
        String funCodes = jsonObject.get("funCodes").toString();//功能code,多个code  ","  分隔
        List<String> existFun = getExistFun(moduleCode);
        List<String> newFunCodes = new ArrayList<String>(Arrays.asList(funCodes.split(",")));//目前的功能code
        List<String> oldFunCodes = new ArrayList<String>(existFun);//构建existFun的副本
        oldFunCodes.removeAll(newFunCodes);// 去除相同元素--->>需要删除的功能code
        newFunCodes.removeAll(existFun);// 去除相同元素---->>需要添加的功能code
        //先删除权限在添加...
        for(String delCode: oldFunCodes){
            moduleFunctionDao.delete(delCode, moduleCode);
        }
        for(String addCode:newFunCodes){
            ModuleFunction moduleFunction = new ModuleFunction();
            moduleFunction.setFunctionId(addCode);
            moduleFunction.setModuleId(moduleCode);
            moduleFunctionDao.save(moduleFunction);
        }
    }
}

+ 142 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/base/ModuleService.java

@ -0,0 +1,142 @@
package com.yihu.jw.business.base.service.base;
import com.yihu.jw.business.base.dao.base.ModuleDao;
import com.yihu.jw.business.base.dao.base.SaasModuleDao;
import com.yihu.jw.business.base.model.base.Module;
import com.yihu.jw.business.base.model.base.SaasModule;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.restmodel.base.base.MModule;
import com.yihu.jw.restmodel.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * Created by chenweida on 2017/5/19.
 */
@Service
public class ModuleService extends BaseJpaService<Module, ModuleDao> {
    @Autowired
    private ModuleDao moduleDao;
    @Autowired
    private SaasModuleDao saasModuleDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Transactional
    public Module createModule(Module module) throws ApiException {
        if (StringUtils.isEmpty(module.getCode())) {
            throw new ApiException(BaseContants.Module.message_fail_code_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(module.getName())) {
            throw new ApiException(BaseContants.Module.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(module.getSaasId())) {
            throw new ApiException(BaseContants.Module.message_fail_saasid_is_null, CommonContants.common_error_params_code);
        }
        Module moduleTmp = moduleDao.findByName(module.getName());
        if (moduleTmp != null) {
            throw new ApiException(BaseContants.Module.message_fail_name_exist, CommonContants.common_error_params_code);
        }
        return moduleDao.save(module);
    }
    @Transactional
    public Module updateModule(Module module) {
        if (StringUtils.isEmpty(module.getCode())) {
            throw new ApiException(BaseContants.Module.message_fail_code_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(module.getName())) {
            throw new ApiException(BaseContants.Module.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(module.getId())) {
            throw new ApiException(BaseContants.Module.message_fail_id_is_null, CommonContants.common_error_params_code);
        }
        Module moduleTmp = moduleDao.findByNameExcludeCode(module.getName(), module.getCode());
        if (moduleTmp != null) {
            throw new ApiException(BaseContants.Module.message_fail_name_exist, CommonContants.common_error_params_code);
        }
        return moduleDao.save(module);
    }
    public Module findByCode(String code) {
        Module module = moduleDao.findByCode(code);
        if (module == null) {
            throw new ApiException(BaseContants.Module.message_fail_code_no_exist, CommonContants.common_error_params_code);
        }
        return module;
    }
    @Transactional
    public void deleteModule(String code) {
        Module module = moduleDao.findByCode(code);
        if (module == null) {
            throw new ApiException(BaseContants.Module.message_fail_code_no_exist, CommonContants.common_error_params_code);
        }
        module.setStatus(-1);
    }
    @Transactional
    public void assignModule(String saasCode, String moduleCodes) {
        //先删除原来已经分配好的模块
        saasModuleDao.deleteBySaasCode(saasCode);
        //分配新的模块
        String [] moduleCodeArr=moduleCodes.split(",");
        List<SaasModule> saasModuleList=new ArrayList<>();
        for(String moduleCode:moduleCodeArr){
            SaasModule saasModule=new SaasModule();
            saasModule.setModuleId(moduleCode);
            saasModule.setSaasId(saasCode);
            saasModuleList.add(saasModule);
        }
        saasModuleDao.save(saasModuleList);
    }
    public List<MModule> getSaasModules(String saasCode) {
        String sql=" select m.code,m.parent_code,m.name from base_module m,base_saas_module sm where m.code=sm.module_id and m.status=1 and sm.saas_id=?";
       return jdbcTemplate.queryForList(sql,MModule.class,saasCode);
    }
    public List<Module> getChildren(String code){
        List<Module> childrens = moduleDao.getChildren(code);
        for(Module children:childrens){
            List<Module> children1 = moduleDao.getChildren(children.getCode());//判断子节点是否有孙节点
            //没有children    state
            //“open”表示是子节点,“closed”表示为父节点;
            if (children1.size()>0){
                children.setState("closed");
            }else{
                children.setState("open");
            }
        }
        return childrens;
    }
    public List<Module> findAll(){
        return moduleDao.findAll();
    }
    /**
     * key为code ,value为模块名称
     * @return
     */
    public Map<String,String> getName(){
        List<Module> modules = findAll();
        Map<String, String> map = new HashMap<>();
        if(null!=modules){
            for(Module module: modules){
                map.put(module.getCode(),module.getName());
            }
        }
        return map;
    }
}

+ 73 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/base/service/base/SaasService.java

@ -0,0 +1,73 @@
package com.yihu.jw.business.base.service.base;
import com.yihu.jw.business.base.dao.base.SaasDao;
import com.yihu.jw.business.base.model.base.Saas;
import com.yihu.jw.mysql.query.BaseJpaService;
import com.yihu.jw.restmodel.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
/**
 * Created by chenweida on 2017/5/19.
 */
@Service
public class SaasService extends BaseJpaService<Saas, SaasDao> {
    @Autowired
    private SaasDao saasDao;
    @Transactional
    public Saas createSaas(Saas saas) throws ApiException {
        if (StringUtils.isEmpty(saas.getCode())) {
            throw new ApiException(BaseContants.Saas.message_fail_code_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(saas.getName())) {
            throw new ApiException(BaseContants.Saas.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        Saas saasTmp = saasDao.findByName(saas.getName());
        if (saasTmp != null) {
            throw new ApiException(BaseContants.Saas.message_fail_name_exist, CommonContants.common_error_params_code);
        }
        return saasDao.save(saas);
    }
    @Transactional
    public Saas updateSaas(Saas saas) {
        if (StringUtils.isEmpty(saas.getCode())) {
            throw new ApiException(BaseContants.Saas.message_fail_code_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(saas.getName())) {
            throw new ApiException(BaseContants.Saas.message_fail_name_is_null, CommonContants.common_error_params_code);
        }
        if (StringUtils.isEmpty(saas.getId())) {
            throw new ApiException(BaseContants.Saas.message_fail_id_is_null, CommonContants.common_error_params_code);
        }
        Saas saasTmp = saasDao.findByNameExcludeCode(saas.getName(), saas.getCode());
        if (saasTmp != null) {
            throw new ApiException(BaseContants.Saas.message_fail_name_exist, CommonContants.common_error_params_code);
        }
        return saasDao.save(saas);
    }
    public Saas findByCode(String code) {
        Saas saas = saasDao.findByCode(code);
        if (saas == null) {
            throw new ApiException(BaseContants.Saas.message_fail_code_no_exist, CommonContants.common_error_params_code);
        }
        return saas;
    }
    @Transactional
    public void deleteSaas(String code) {
        Saas saas = saasDao.findByCode(code);
        if (saas == null) {
            throw new ApiException(BaseContants.Saas.message_fail_code_no_exist, CommonContants.common_error_params_code);
        }
        saas.setStatus(-1);
    }
    public Saas findByName(String cityName) {
        return saasDao.findByName(cityName);
    }
}