|
@ -1,20 +1,30 @@
|
|
package com.yihu.hos.system.service;
|
|
package com.yihu.hos.system.service;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
import com.yihu.hos.common.constants.ContextAttributes;
|
|
import com.yihu.hos.config.MongoConfig;
|
|
import com.yihu.hos.config.MongoConfig;
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
import com.yihu.hos.core.datatype.StringUtil;
|
|
import com.yihu.hos.core.encrypt.DES;
|
|
import com.yihu.hos.core.encrypt.DES;
|
|
|
|
import com.yihu.hos.core.log.Logger;
|
|
|
|
import com.yihu.hos.core.log.LoggerFactory;
|
|
|
|
import com.yihu.hos.interceptor.LocalContext;
|
|
import com.yihu.hos.system.dao.AppDao;
|
|
import com.yihu.hos.system.dao.AppDao;
|
|
import com.yihu.hos.system.dao.AppServiceDao;
|
|
import com.yihu.hos.system.dao.AppServiceDao;
|
|
import com.yihu.hos.system.model.SystemApp;
|
|
import com.yihu.hos.system.model.SystemApp;
|
|
import com.yihu.hos.system.model.SystemServiceEndpoint;
|
|
import com.yihu.hos.system.model.SystemServiceEndpoint;
|
|
|
|
import com.yihu.hos.web.framework.constant.EndPointConstant;
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
import com.yihu.hos.web.framework.model.Result;
|
|
import com.yihu.hos.web.framework.util.GridFSUtil;
|
|
import com.yihu.hos.web.framework.util.GridFSUtil;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
|
|
|
import org.zbus.broker.ZbusBroker;
|
|
|
|
import org.zbus.mq.Producer;
|
|
|
|
import org.zbus.net.http.Message;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
import java.util.UUID;
|
|
@ -26,7 +36,7 @@ import java.util.UUID;
|
|
@Service("appManager")
|
|
@Service("appManager")
|
|
public class AppManager {
|
|
public class AppManager {
|
|
public static final String BEAN_ID = "appManager";
|
|
public static final String BEAN_ID = "appManager";
|
|
|
|
|
|
|
|
static final Logger logger = LoggerFactory.getLogger(AppManager.class);
|
|
@Resource(name = AppDao.BEAN_ID)
|
|
@Resource(name = AppDao.BEAN_ID)
|
|
private AppDao appDao;
|
|
private AppDao appDao;
|
|
|
|
|
|
@ -36,14 +46,23 @@ public class AppManager {
|
|
@Autowired
|
|
@Autowired
|
|
private MongoConfig mongoConfig;
|
|
private MongoConfig mongoConfig;
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
|
|
|
private ZbusBroker zbusBroker;
|
|
|
|
|
|
|
|
public void setZbusBroker(ZbusBroker zbusBroker) {
|
|
|
|
this.zbusBroker = zbusBroker;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result getAppList(Map<String, Object> params) throws Exception {
|
|
public Result getAppList(Map<String, Object> params) throws Exception {
|
|
return appDao.getAppList(params);
|
|
return appDao.getAppList(params);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SystemApp getAppById(String id) throws Exception {
|
|
public SystemApp getAppById(String id) throws Exception {
|
|
return appDao.getEntity(SystemApp.class,id);
|
|
|
|
|
|
return appDao.getEntity(SystemApp.class, id);
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@ -79,14 +98,13 @@ public class AppManager {
|
|
/* ==============================服务模块================================= */
|
|
/* ==============================服务模块================================= */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result getAppServiceList(Map<String, Object> params) throws Exception {
|
|
public Result getAppServiceList(Map<String, Object> params) throws Exception {
|
|
return appServiceDao.getAppServiceList(params);
|
|
return appServiceDao.getAppServiceList(params);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public SystemServiceEndpoint getAppServiceById(String id) throws Exception {
|
|
public SystemServiceEndpoint getAppServiceById(String id) throws Exception {
|
|
SystemServiceEndpoint serviceEndpoint = appServiceDao.getEntity(SystemServiceEndpoint.class,id);
|
|
|
|
|
|
SystemServiceEndpoint serviceEndpoint = appServiceDao.getEntity(SystemServiceEndpoint.class, id);
|
|
serviceEndpoint.setRequesModule(serviceEndpoint.getRequesModule().replaceAll("\n", "<br>"));
|
|
serviceEndpoint.setRequesModule(serviceEndpoint.getRequesModule().replaceAll("\n", "<br>"));
|
|
serviceEndpoint.setResponeResult(serviceEndpoint.getResponeResult().replaceAll("\n", "<br>"));
|
|
serviceEndpoint.setResponeResult(serviceEndpoint.getResponeResult().replaceAll("\n", "<br>"));
|
|
serviceEndpoint.setResponeError(serviceEndpoint.getResponeError().replaceAll("\n", "<br>"));
|
|
serviceEndpoint.setResponeError(serviceEndpoint.getResponeError().replaceAll("\n", "<br>"));
|
|
@ -95,8 +113,9 @@ public class AppManager {
|
|
}
|
|
}
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
public Result addAppService(SystemServiceEndpoint obj) throws Exception {
|
|
|
|
appServiceDao.saveEntity(obj);
|
|
|
|
|
|
public Result addAppService(SystemServiceEndpoint endpoint) throws Exception {
|
|
|
|
appServiceDao.saveEntity(endpoint);
|
|
|
|
this.sendMsg(EndPointConstant.ADD_ENDPOINT, endpoint);
|
|
return Result.success("保存成功");
|
|
return Result.success("保存成功");
|
|
}
|
|
}
|
|
|
|
|
|
@ -126,18 +145,18 @@ public class AppManager {
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
public Result deleteAppService(String id) throws Exception {
|
|
public Result deleteAppService(String id) throws Exception {
|
|
SystemServiceEndpoint systemApp = appServiceDao.getEntity(SystemServiceEndpoint.class, id);
|
|
|
|
appServiceDao.deleteEntity(systemApp);
|
|
|
|
|
|
SystemServiceEndpoint endpoint = appServiceDao.getEntity(SystemServiceEndpoint.class, id);
|
|
|
|
appServiceDao.deleteEntity(endpoint);
|
|
|
|
this.sendMsg(EndPointConstant.DELETE_ENDPOINT, endpoint);
|
|
return Result.success("删除成功");
|
|
return Result.success("删除成功");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result uploadFile(CommonsMultipartFile file) {
|
|
public Result uploadFile(CommonsMultipartFile file) {
|
|
String newFileName;
|
|
String newFileName;
|
|
try {
|
|
try {
|
|
String fileName = UUID.randomUUID() + file.getFileItem().getName();
|
|
String fileName = UUID.randomUUID() + file.getFileItem().getName();
|
|
newFileName = GridFSUtil.uploadFile(file.getInputStream() ,fileName,null);
|
|
|
|
|
|
newFileName = GridFSUtil.uploadFile(file.getInputStream(), fileName, null);
|
|
if (!StringUtil.isEmpty(newFileName)) {
|
|
if (!StringUtil.isEmpty(newFileName)) {
|
|
return Result.success(DES.encrypt(newFileName, DES.COMMON_PASSWORD));
|
|
return Result.success(DES.encrypt(newFileName, DES.COMMON_PASSWORD));
|
|
}
|
|
}
|
|
@ -147,7 +166,7 @@ public class AppManager {
|
|
return Result.error("上传失败");
|
|
return Result.error("上传失败");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result readFile(OutputStream os, String fileName) {
|
|
public Result readFile(OutputStream os, String fileName) {
|
|
String dbName = "upload";
|
|
String dbName = "upload";
|
|
try {
|
|
try {
|
|
@ -159,4 +178,28 @@ public class AppManager {
|
|
}
|
|
}
|
|
return Result.error("读取失败");
|
|
return Result.error("读取失败");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void sendMsg(String event, SystemServiceEndpoint endpoint) {
|
|
|
|
if (zbusBroker == null) {
|
|
|
|
logger.error("zbusBroker is null.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
String msg = objectMapper.writeValueAsString(endpoint);
|
|
|
|
String tenant = LocalContext.getContext().getAttachment(ContextAttributes.TENANT_NAME);
|
|
|
|
|
|
|
|
Producer producer = new Producer(zbusBroker, EndPointConstant.ZBUS_MQ + "@" + tenant);
|
|
|
|
producer.createMQ(); //确定为创建消息队列需要显示调用
|
|
|
|
Message message = new Message();
|
|
|
|
message.setHead("event", event);
|
|
|
|
message.setHead("tenant", tenant);
|
|
|
|
message.setMethod("POST");
|
|
|
|
message.setBody(msg);
|
|
|
|
producer.sendSync(message);
|
|
|
|
} catch (IOException | InterruptedException e) {
|
|
|
|
logger.error(e.getMessage());
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|