mirror of https://gitee.com/maxjhandsome/pig
微调README
This commit is contained in:
commit
d50c665b3d
55
doc/pig.sql
55
doc/pig.sql
File diff suppressed because one or more lines are too long
|
@ -17,9 +17,14 @@ public interface MqQueueConstant {
|
|||
String MOBILE_CODE_QUEUE = "mobile_code_queue";
|
||||
|
||||
/**
|
||||
* 服务状态队列
|
||||
* 短信服务状态队列
|
||||
*/
|
||||
String SERVICE_STATUS_CHANGE = "service_status_change";
|
||||
String MOBILE_SERVICE_STATUS_CHANGE = "mobile_service_status_change";
|
||||
|
||||
/**
|
||||
* 钉钉服务状态队列
|
||||
*/
|
||||
String DINGTALK_SERVICE_STATUS_CHANGE = "dingtalk_service_status_change";
|
||||
|
||||
/**
|
||||
* zipkin 队列
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package com.github.pig.common.util.template;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/1/15
|
||||
* 钉钉消息模板
|
||||
* msgtype : text
|
||||
* text : {"content":"服务: pig-upms-service 状态:UP"}
|
||||
*/
|
||||
@Data
|
||||
@ToString
|
||||
public class DingTalkMsgTemplate implements Serializable {
|
||||
private String msgtype;
|
||||
private TextBean text;
|
||||
|
||||
public String getMsgtype() {
|
||||
return msgtype;
|
||||
}
|
||||
|
||||
public void setMsgtype(String msgtype) {
|
||||
this.msgtype = msgtype;
|
||||
}
|
||||
|
||||
public TextBean getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(TextBean text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public static class TextBean {
|
||||
/**
|
||||
* content : 服务: pig-upms-service 状态:UP
|
||||
*/
|
||||
|
||||
private String content;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public void setContent(String content) {
|
||||
this.content = content;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,8 +11,7 @@ spring:
|
|||
server:
|
||||
git:
|
||||
uri: https://gitee.com/cqzqxq_lxh/pig-config.git
|
||||
fail-fast: true
|
||||
|
||||
default-label: ${spring.profiles.active} #解决监控down
|
||||
---
|
||||
spring:
|
||||
profiles: dev
|
||||
|
@ -26,6 +25,9 @@ eureka:
|
|||
defaultZone: http://pig:gip6666@localhost:1025/eureka
|
||||
registry-fetch-interval-seconds: 10
|
||||
|
||||
endpoints:
|
||||
health:
|
||||
sensitive: false
|
||||
---
|
||||
spring:
|
||||
profiles: prd
|
||||
|
|
|
@ -4,6 +4,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.github.pig.common.constant.CommonConstant;
|
||||
import com.github.pig.common.util.R;
|
||||
import com.github.pig.common.util.exception.PigDeniedException;
|
||||
import com.xiaoleilu.hutool.http.HttpUtil;
|
||||
import com.xiaoleilu.hutool.util.URLUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -24,9 +27,9 @@ import java.io.PrintWriter;
|
|||
* 授权拒绝处理器,覆盖默认的OAuth2AccessDeniedHandler
|
||||
* 包装失败信息到PigDeniedException
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class PigAccessDeniedHandler extends OAuth2AccessDeniedHandler {
|
||||
private static Logger logger = LoggerFactory.getLogger(PigAccessDeniedHandler.class);
|
||||
@Autowired
|
||||
private ObjectMapper objectMapper;
|
||||
|
||||
|
@ -41,7 +44,7 @@ public class PigAccessDeniedHandler extends OAuth2AccessDeniedHandler {
|
|||
*/
|
||||
@Override
|
||||
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException authException) throws IOException, ServletException {
|
||||
logger.info("授权失败,禁止访问");
|
||||
log.info("授权失败,禁止访问 {}", request.getRequestURI());
|
||||
response.setCharacterEncoding(CommonConstant.UTF8);
|
||||
response.setContentType(CommonConstant.CONTENT_TYPE);
|
||||
R<String> result = new R<>(new PigDeniedException("授权失败,禁止访问"));
|
||||
|
|
|
@ -5,6 +5,8 @@ import com.github.pig.common.vo.MenuVO;
|
|||
import com.github.pig.gateway.feign.MenuService;
|
||||
import com.github.pig.gateway.service.PermissionService;
|
||||
import com.xiaoleilu.hutool.collection.CollectionUtil;
|
||||
import com.xiaoleilu.hutool.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
|
@ -20,6 +22,7 @@ import java.util.Set;
|
|||
* @author lengleng
|
||||
* @date 2017/10/28
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("permissionService")
|
||||
public class PermissionServiceImpl implements PermissionService {
|
||||
@Autowired
|
||||
|
@ -39,12 +42,15 @@ public class PermissionServiceImpl implements PermissionService {
|
|||
|
||||
if (principal != null) {
|
||||
if (CollectionUtil.isEmpty(grantedAuthorityList)) {
|
||||
log.warn("角色列表为空:{}", authentication.getPrincipal());
|
||||
return hasPermission;
|
||||
}
|
||||
|
||||
Set<MenuVO> urls = new HashSet<>();
|
||||
for (SimpleGrantedAuthority authority : grantedAuthorityList) {
|
||||
urls.addAll(menuService.findMenuByRole(authority.getAuthority()));
|
||||
if (!StrUtil.equals(authority.getAuthority(), "ROLE_USER")) {
|
||||
urls.addAll(menuService.findMenuByRole(authority.getAuthority()));
|
||||
}
|
||||
}
|
||||
|
||||
for (MenuVO menu : urls) {
|
||||
|
|
|
@ -11,7 +11,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
* 测试Job
|
||||
*/
|
||||
@Slf4j
|
||||
@ElasticJobConfig(cron = "0/2 * * * * ?", shardingTotalCount = 3,
|
||||
@ElasticJobConfig(cron = "0 0 0/1 * * ?", shardingTotalCount = 3,
|
||||
shardingItemParameters = "0=pig1,1=pig2,2=pig3",
|
||||
startedTimeoutMilliseconds = 5000L,
|
||||
completedTimeoutMilliseconds = 10000L,
|
||||
|
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||
* @author lengleng
|
||||
* @date 2018/2/8
|
||||
*/
|
||||
@ElasticJobConfig(cron = "0/2 * * * * ?", shardingTotalCount = 3, shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou")
|
||||
@ElasticJobConfig(cron = "0 0 0/1 * * ? ", shardingTotalCount = 3, shardingItemParameters = "0=Beijing,1=Shanghai,2=Guangzhou")
|
||||
public class PigDataflowJob implements DataflowJob<Integer> {
|
||||
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import lombok.extern.slf4j.Slf4j;
|
|||
* 测试Job
|
||||
*/
|
||||
@Slf4j
|
||||
@ElasticJobConfig(cron = "0/2 * * * * ?", shardingTotalCount = 3,
|
||||
@ElasticJobConfig(cron = "0 0 0/1 * * ?", shardingTotalCount = 3,
|
||||
shardingItemParameters = "0=pig1,1=pig2,2=pig3",
|
||||
startedTimeoutMilliseconds = 5000L,
|
||||
completedTimeoutMilliseconds = 10000L,
|
||||
|
|
|
@ -30,11 +30,14 @@
|
|||
</dependency>
|
||||
<!--阿里大于-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.taobao</groupId>
|
||||
<artifactId>alidayu-sms</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/src/main/resources/lib/alidayu-sms-1.0.jar</systemPath>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-core</artifactId>
|
||||
<version>3.2.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>aliyun-java-sdk-dysmsapi</artifactId>
|
||||
<version>1.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -47,27 +50,7 @@
|
|||
<finalName>${project.name}</finalName>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
<encoding>UTF-8</encoding>
|
||||
<compilerArguments>
|
||||
<extdirs>${basedir}/src/main/resources/lib</extdirs>
|
||||
</compilerArguments>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>BOOT-INF/lib/</targetPath>
|
||||
<directory>${basedir}/src/main/resources/lib/</directory>
|
||||
<includes>
|
||||
<include>**/*.jar</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.github.pig.mc.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/4/2
|
||||
* 钉钉服务配置
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "sms.dingtalk")
|
||||
public class DingTalkPropertiesConfig {
|
||||
/**
|
||||
* webhook
|
||||
*/
|
||||
private String webhook;
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.github.pig.mc.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pig.common.util.template.DingTalkMsgTemplate;
|
||||
import com.github.pig.mc.config.DingTalkPropertiesConfig;
|
||||
import com.xiaoleilu.hutool.http.HttpUtil;
|
||||
import com.xiaoleilu.hutool.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/4/22
|
||||
* 发送钉钉消息逻辑
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class DingTalkMessageHandler {
|
||||
@Autowired
|
||||
private DingTalkPropertiesConfig dingTalkPropertiesConfig;
|
||||
|
||||
/**
|
||||
* 业务处理
|
||||
*
|
||||
* @param text 消息
|
||||
*/
|
||||
public boolean process(String text) {
|
||||
String webhook = dingTalkPropertiesConfig.getWebhook();
|
||||
if (StrUtil.isBlank(webhook)) {
|
||||
log.error("钉钉配置错误,webhook为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
DingTalkMsgTemplate dingTalkMsgTemplate = new DingTalkMsgTemplate();
|
||||
dingTalkMsgTemplate.setMsgtype("text");
|
||||
DingTalkMsgTemplate.TextBean textBean = new DingTalkMsgTemplate.TextBean();
|
||||
textBean.setContent(text);
|
||||
dingTalkMsgTemplate.setText(textBean);
|
||||
String result = HttpUtil.post(webhook, JSONObject.toJSONString(dingTalkMsgTemplate));
|
||||
log.info("钉钉提醒成功,报文响应:{}", result);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +1,19 @@
|
|||
package com.github.pig.mc.handler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.aliyuncs.profile.IClientProfile;
|
||||
import com.github.pig.common.constant.CommonConstant;
|
||||
import com.github.pig.common.util.Assert;
|
||||
import com.github.pig.common.util.template.MobileMsgTemplate;
|
||||
import com.github.pig.mc.config.SmsAliyunPropertiesConfig;
|
||||
import com.github.pig.mc.utils.constant.SmsChannelTemplateConstant;
|
||||
import com.github.pig.mc.utils.sms.EnumSmsChannelTemplate;
|
||||
import com.taobao.api.DefaultTaobaoClient;
|
||||
import com.taobao.api.TaobaoClient;
|
||||
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
|
||||
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -25,7 +28,8 @@ import org.springframework.stereotype.Component;
|
|||
public class SmsAliyunMessageHandler extends AbstractMessageHandler {
|
||||
@Autowired
|
||||
private SmsAliyunPropertiesConfig smsAliyunPropertiesConfig;
|
||||
private static final String URL = "http://gw.api.taobao.com/router/rest";
|
||||
private static final String product = "Dysmsapi";
|
||||
private static final String domain = "dysmsapi.aliyuncs.com";
|
||||
|
||||
/**
|
||||
* 数据校验
|
||||
|
@ -45,43 +49,43 @@ public class SmsAliyunMessageHandler extends AbstractMessageHandler {
|
|||
*/
|
||||
@Override
|
||||
public boolean process(MobileMsgTemplate mobileMsgTemplate) {
|
||||
// 配置连接参数URL、KEY、SECRET
|
||||
TaobaoClient taobaoClient = new DefaultTaobaoClient(URL, smsAliyunPropertiesConfig.getAccessKey(), smsAliyunPropertiesConfig.getSecretKey());
|
||||
// 配置请求参数
|
||||
AlibabaAliqinFcSmsNumSendRequest request = new AlibabaAliqinFcSmsNumSendRequest();
|
||||
/**
|
||||
* 公共回传参数,在“消息返回”中会透传回该参数;举例:用户可以传入自己下级的会员ID,在消息返回时,该会员ID会包含在内,用户可以根据该会员ID识别是哪位会员使用了你的应用
|
||||
*/
|
||||
request.setExtend(mobileMsgTemplate.getMobile());
|
||||
/**
|
||||
* 短信接收号码。支持单个或多个手机号码,传入号码为11位手机号码,不能入加0或+86。群发短信需传多个号码,以英文逗号分隔,一次调用最多传入200个号码。示例:18600000000,13911111111,13322222222
|
||||
*/
|
||||
request.setRecNum(mobileMsgTemplate.getMobile());
|
||||
/**
|
||||
* 短信签名,传入的短信签名必须是在阿里大鱼“管理中心-短信签名管理”中的可用签名。如“阿里大鱼”已在短信签名管理中通过审核,则可传入”阿里大鱼“(传参时去掉引号)作为短信签名。短信效果示例:【阿里大鱼】欢迎使用阿里大鱼服务。
|
||||
*/
|
||||
request.setSmsFreeSignName(EnumSmsChannelTemplate.LOGIN_NAME_LOGIN.getDescription());
|
||||
/**
|
||||
* 短信模板变量,传参规则{"key":"value"},key的名字须和申请模板中的变量名一致,多个变量之间以逗号隔开。示例:针对模板“验证码${code},您正在进行${product}身份验证,打死不要告诉别人哦!”,传参时需传入{"code":"1234","product":"alidayu"}
|
||||
*/
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("product","pig_cloud");
|
||||
jsonObject.put("code",mobileMsgTemplate.getText());
|
||||
request.setSmsParamString(jsonObject.toString());
|
||||
/**
|
||||
* 短信模板ID,传入的模板必须是在阿里大鱼“管理中心-短信模板管理”中的可用模板。示例:SMS_585014
|
||||
*/
|
||||
request.setSmsTemplateCode(smsAliyunPropertiesConfig.getChannels().get(SmsChannelTemplateConstant.LOGIN_NAME_LOGIN));
|
||||
/**
|
||||
* 短信类型,传入值请填写normal
|
||||
*/
|
||||
request.setSmsType("normal");
|
||||
//可自助调整超时时间
|
||||
System.setProperty("sun.net.client.defaultConnectTimeout", "10000");
|
||||
System.setProperty("sun.net.client.defaultReadTimeout", "10000");
|
||||
|
||||
//初始化acsClient,暂不支持region化
|
||||
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", smsAliyunPropertiesConfig.getAccessKey(), smsAliyunPropertiesConfig.getSecretKey());
|
||||
try {
|
||||
AlibabaAliqinFcSmsNumSendResponse response = taobaoClient.execute(request);
|
||||
return response.getResult().getSuccess();
|
||||
}catch (Exception e){
|
||||
return false;
|
||||
DefaultProfile.addEndpoint("cn-hou", "cn-hangzhou", product, domain);
|
||||
} catch (ClientException e) {
|
||||
log.error("初始化SDK 异常", e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
IAcsClient acsClient = new DefaultAcsClient(profile);
|
||||
|
||||
//组装请求对象-具体描述见控制台-文档部分内容
|
||||
SendSmsRequest request = new SendSmsRequest();
|
||||
//必填:待发送手机号
|
||||
request.setPhoneNumbers(mobileMsgTemplate.getMobile());
|
||||
//必填:短信签名-可在短信控制台中找到
|
||||
request.setSignName(EnumSmsChannelTemplate.LOGIN_NAME_LOGIN.getDescription());
|
||||
//必填:短信模板-可在短信控制台中找到
|
||||
request.setTemplateCode(smsAliyunPropertiesConfig.getChannels().get(SmsChannelTemplateConstant.LOGIN_NAME_LOGIN));
|
||||
//可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("product", "pig_cloud");
|
||||
jsonObject.put("code", mobileMsgTemplate.getText());
|
||||
request.setTemplateParam(jsonObject.toJSONString());
|
||||
request.setOutId(mobileMsgTemplate.getMobile());
|
||||
|
||||
//hint 此处可能会抛出异常,注意catch
|
||||
try {
|
||||
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
||||
} catch (ClientException e) {
|
||||
log.error("发送异常");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.github.pig.mc.listener;
|
||||
|
||||
import com.github.pig.common.constant.MqQueueConstant;
|
||||
import com.github.pig.common.util.template.DingTalkMsgTemplate;
|
||||
import com.github.pig.mc.handler.DingTalkMessageHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/4/22
|
||||
* 监听服务状态改变发送请求
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RabbitListener(queues = MqQueueConstant.DINGTALK_SERVICE_STATUS_CHANGE)
|
||||
public class DingTalkServiceChangeReceiveListener {
|
||||
@Autowired
|
||||
private DingTalkMessageHandler dingTalkMessageHandler;
|
||||
|
||||
@RabbitHandler
|
||||
public void receive(String text) {
|
||||
long startTime = System.currentTimeMillis();
|
||||
log.info("消息中心接收到钉钉发送请求-> 内容:{} ", text);
|
||||
dingTalkMessageHandler.process(text);
|
||||
long useTime = System.currentTimeMillis() - startTime;
|
||||
log.info("调用 钉钉网关处理完毕,耗时 {}毫秒", useTime);
|
||||
}
|
||||
}
|
|
@ -14,8 +14,8 @@ import org.springframework.stereotype.Component;
|
|||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
@RabbitListener(queues = MqQueueConstant.SERVICE_STATUS_CHANGE)
|
||||
public class ServiceChangeReceiveListener {
|
||||
@RabbitListener(queues = MqQueueConstant.MOBILE_SERVICE_STATUS_CHANGE)
|
||||
public class MobileServiceChangeReceiveListener {
|
||||
@RabbitHandler
|
||||
public void receive(MobileMsgTemplate mobileMsgTemplate) {
|
||||
long startTime = System.currentTimeMillis();
|
Binary file not shown.
|
@ -38,8 +38,13 @@ public class RabbitConfig {
|
|||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Queue initServiceStatusChangeQueue() {
|
||||
return new Queue(MqQueueConstant.SERVICE_STATUS_CHANGE);
|
||||
public Queue initMobileServiceStatusChangeQueue() {
|
||||
return new Queue(MqQueueConstant.MOBILE_SERVICE_STATUS_CHANGE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Queue initDingTalkServiceStatusChangeQueue() {
|
||||
return new Queue(MqQueueConstant.DINGTALK_SERVICE_STATUS_CHANGE);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
|
@ -33,7 +32,7 @@ public class MenuController extends BaseController {
|
|||
* @return 菜单列表
|
||||
*/
|
||||
@GetMapping("/findMenuByRole/{role}")
|
||||
public Set<MenuVO> findMenuByRole(@PathVariable String role) {
|
||||
public List<MenuVO> findMenuByRole(@PathVariable String role) {
|
||||
return sysMenuService.findMenuByRole(role);
|
||||
}
|
||||
|
||||
|
@ -65,7 +64,7 @@ public class MenuController extends BaseController {
|
|||
*/
|
||||
@GetMapping("/userTree")
|
||||
public List<Integer> userTree() {
|
||||
Set<MenuVO> menus = sysMenuService.findMenuByRole(getRole().get(0));
|
||||
List<MenuVO> menus = sysMenuService.findMenuByRole(getRole().get(0));
|
||||
List<Integer> menuList = new ArrayList<>();
|
||||
for (MenuVO menuVo : menus) {
|
||||
menuList.add(menuVo.getMenuId());
|
||||
|
@ -81,7 +80,7 @@ public class MenuController extends BaseController {
|
|||
*/
|
||||
@GetMapping("/roleTree/{roleName}")
|
||||
public List<Integer> roleTree(@PathVariable String roleName) {
|
||||
Set<MenuVO> menus = sysMenuService.findMenuByRole(roleName);
|
||||
List<MenuVO> menus = sysMenuService.findMenuByRole(roleName);
|
||||
List<Integer> menuList = new ArrayList<>();
|
||||
for (MenuVO menuVo : menus) {
|
||||
menuList.add(menuVo.getMenuId());
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.github.pig.admin.model.entity.SysMenu;
|
|||
import com.github.pig.common.vo.MenuVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
|
@ -23,5 +24,5 @@ public interface SysMenuMapper extends BaseMapper<SysMenu> {
|
|||
* @param role 角色名称
|
||||
* @return 菜单列表
|
||||
*/
|
||||
Set<MenuVO> findMenuByRoleName(@Param("role") String role);
|
||||
List<MenuVO> findMenuByRoleName(@Param("role") String role);
|
||||
}
|
|
@ -7,7 +7,6 @@ import com.github.pig.admin.model.entity.SysMenu;
|
|||
import com.github.pig.common.vo.MenuVO;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
|
@ -24,7 +23,7 @@ public interface SysMenuService extends IService<SysMenu> {
|
|||
* @param role 角色名称
|
||||
* @return 菜单列表
|
||||
*/
|
||||
Set<MenuVO> findMenuByRole(String role);
|
||||
List<MenuVO> findMenuByRole(String role);
|
||||
|
||||
/**
|
||||
* 通过角色获取菜单权限列表
|
||||
|
|
|
@ -36,7 +36,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
|
||||
@Override
|
||||
@Cacheable(value = "menu_details", key = "#role + '_menu'")
|
||||
public Set<MenuVO> findMenuByRole(String role) {
|
||||
public List<MenuVO> findMenuByRole(String role) {
|
||||
return sysMenuMapper.findMenuByRoleName(role);
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
public String[] findPermission(String[] roles) {
|
||||
Set<MenuVO> menuVoSet = new HashSet<>();
|
||||
for (String role : roles) {
|
||||
Set<MenuVO> menuVos = findMenuByRole(role);
|
||||
List<MenuVO> menuVos = findMenuByRole(role);
|
||||
menuVoSet.addAll(menuVos);
|
||||
}
|
||||
|
||||
|
@ -92,9 +92,9 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
@Override
|
||||
public List<MenuTree> findUserMenuTree(String roleName) {
|
||||
// 获取符合条件得菜单
|
||||
Set<MenuVO> all = findMenuByRole(roleName);
|
||||
List<MenuVO> all = findMenuByRole(roleName);
|
||||
final List<MenuTree> menuTreeList = new ArrayList<>();
|
||||
all.stream().forEach((menuVo -> {
|
||||
all.forEach((menuVo -> {
|
||||
if (CommonConstant.MENU.equals(menuVo.getType())) {
|
||||
menuTreeList.add(new MenuTree(menuVo));
|
||||
}
|
||||
|
|
|
@ -48,5 +48,6 @@
|
|||
sys_role.del_flag = 0
|
||||
AND sys_menu.del_flag = 0
|
||||
AND sys_role.role_code = #{role}
|
||||
ORDER BY sys_menu.sort DESC
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -14,15 +14,15 @@ public class PigAdminApplicationTest {
|
|||
|
||||
@Test
|
||||
public void testEnvironmentProperties() {
|
||||
System.out.println(stringEncryptor.encrypt("redis"));
|
||||
System.out.println(stringEncryptor.encrypt("pig"));
|
||||
// System.out.println(stringEncryptor.encrypt("redis"));
|
||||
// System.out.println(stringEncryptor.encrypt("pig"));
|
||||
System.out.println(stringEncryptor.encrypt("lengleng"));
|
||||
System.out.println(stringEncryptor.encrypt("root"));
|
||||
System.out.println(stringEncryptor.encrypt("g0HJr2Ltrs0k6tJDY6pDI2aVMUCPSWZDTROLcFMs"));
|
||||
System.out.println(stringEncryptor.encrypt("24760324"));
|
||||
System.out.println(stringEncryptor.encrypt("175d516debb916d3842d981dd3b76061"));
|
||||
System.out.println(stringEncryptor.encrypt("101322838"));
|
||||
System.out.println(stringEncryptor.encrypt("fe6ec1ed3fc45e664ce8ddbf78376ab7"));
|
||||
// System.out.println(stringEncryptor.encrypt("g0HJr2Ltrs0k6tJDY6pDI2aVMUCPSWZDTROLcFMs"));
|
||||
// System.out.println(stringEncryptor.encrypt("24760324"));
|
||||
// System.out.println(stringEncryptor.encrypt("175d516debb916d3842d981dd3b76061"));
|
||||
// System.out.println(stringEncryptor.encrypt("101322838"));
|
||||
// System.out.println(stringEncryptor.encrypt("fe6ec1ed3fc45e664ce8ddbf78376ab7"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
package com.github.pig.monitor.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/4/22
|
||||
*/
|
||||
@Data
|
||||
@ConditionalOnExpression("!'${webhook}'.isEmpty()")
|
||||
public class MonitorDingTalkPropertiesConfig {
|
||||
/**
|
||||
* 是否开启钉钉通知
|
||||
*/
|
||||
private Boolean enabled;
|
||||
}
|
|
@ -1,28 +1,18 @@
|
|||
package com.github.pig.monitor.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/1/25
|
||||
* 监控短信接收者列表
|
||||
* @date 2018/4/22
|
||||
*/
|
||||
@Configuration
|
||||
@Data
|
||||
@ConditionalOnExpression("!'${mobiles}'.isEmpty()")
|
||||
@ConfigurationProperties(prefix = "mobiles")
|
||||
public class MonitorMobilePropertiesConfig {
|
||||
private List<String> users = new ArrayList<>();
|
||||
|
||||
public List<String> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(List<String> users) {
|
||||
this.users = users;
|
||||
}
|
||||
private Boolean enabled;
|
||||
private List<String> mobiles = new ArrayList<>();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.github.pig.monitor.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/1/25
|
||||
* 监控配置
|
||||
*/
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "notifier")
|
||||
public class MonitorPropertiesConfig {
|
||||
|
||||
private MonitorMobilePropertiesConfig mobile;
|
||||
|
||||
private MonitorDingTalkPropertiesConfig dingTalk;
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.pig.monitor.config;
|
||||
|
||||
import com.github.pig.monitor.filter.MobileNotifier;
|
||||
import com.github.pig.monitor.filter.StatusChangeNotifier;
|
||||
import de.codecentric.boot.admin.notify.RemindingNotifier;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -23,7 +23,7 @@ public class PigNotifierConfiguration {
|
|||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
@Autowired
|
||||
private MonitorMobilePropertiesConfig monitorMobilePropertiesConfig;
|
||||
private MonitorPropertiesConfig monitorPropertiesConfig;
|
||||
@Bean
|
||||
@Primary
|
||||
public RemindingNotifier remindingNotifier() {
|
||||
|
@ -33,8 +33,8 @@ public class PigNotifierConfiguration {
|
|||
}
|
||||
|
||||
@Bean
|
||||
public MobileNotifier mobileNotifier(){
|
||||
return new MobileNotifier(monitorMobilePropertiesConfig,rabbitTemplate);
|
||||
public StatusChangeNotifier mobileNotifier(){
|
||||
return new StatusChangeNotifier(monitorPropertiesConfig,rabbitTemplate);
|
||||
}
|
||||
|
||||
@Scheduled(fixedRate = 60_000L)
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package com.github.pig.monitor.filter;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.pig.common.constant.MqQueueConstant;
|
||||
import com.github.pig.common.constant.enums.EnumSmsChannel;
|
||||
import com.github.pig.common.util.template.DingTalkMsgTemplate;
|
||||
import com.github.pig.common.util.template.MobileMsgTemplate;
|
||||
import com.github.pig.monitor.config.MonitorMobilePropertiesConfig;
|
||||
import com.github.pig.monitor.config.MonitorPropertiesConfig;
|
||||
import com.xiaoleilu.hutool.collection.CollectionUtil;
|
||||
import com.xiaoleilu.hutool.date.DateUtil;
|
||||
import de.codecentric.boot.admin.event.ClientApplicationEvent;
|
||||
|
@ -14,16 +16,16 @@ import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
|||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2018/1/25
|
||||
* 服务下线手机短信通知
|
||||
* @date 2018/4/22
|
||||
* 服务下线通知
|
||||
*/
|
||||
@Slf4j
|
||||
public class MobileNotifier extends AbstractStatusChangeNotifier {
|
||||
public class StatusChangeNotifier extends AbstractStatusChangeNotifier {
|
||||
public static final String STATUS_CHANGE = "STATUS_CHANGE";
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
private MonitorMobilePropertiesConfig monitorMobilePropertiesConfig;
|
||||
private MonitorPropertiesConfig monitorMobilePropertiesConfig;
|
||||
|
||||
public MobileNotifier(MonitorMobilePropertiesConfig monitorMobilePropertiesConfig, RabbitTemplate rabbitTemplate) {
|
||||
public StatusChangeNotifier(MonitorPropertiesConfig monitorMobilePropertiesConfig, RabbitTemplate rabbitTemplate) {
|
||||
this.rabbitTemplate = rabbitTemplate;
|
||||
this.monitorMobilePropertiesConfig = monitorMobilePropertiesConfig;
|
||||
}
|
||||
|
@ -57,9 +59,21 @@ public class MobileNotifier extends AbstractStatusChangeNotifier {
|
|||
log.info("Application {} ({}) is {}", event.getApplication().getName(),
|
||||
event.getApplication().getId(), ((ClientApplicationStatusChangedEvent) event).getTo().getStatus());
|
||||
String text = String.format("应用:%s 服务ID:%s 下线,时间:%s", event.getApplication().getName(), event.getApplication().getId(), DateUtil.date(event.getTimestamp()).toString());
|
||||
rabbitTemplate.convertAndSend(MqQueueConstant.SERVICE_STATUS_CHANGE,
|
||||
new MobileMsgTemplate(CollectionUtil.join(monitorMobilePropertiesConfig.getUsers(), ","),
|
||||
text, EnumSmsChannel.ALIYUN.getName()));
|
||||
|
||||
//开启短信通知
|
||||
if (monitorMobilePropertiesConfig.getMobile().getEnabled()) {
|
||||
log.info("开始短信通知,内容:{}", text);
|
||||
rabbitTemplate.convertAndSend(MqQueueConstant.MOBILE_SERVICE_STATUS_CHANGE,
|
||||
new MobileMsgTemplate(CollectionUtil.join(monitorMobilePropertiesConfig.getMobile().getMobiles(), ","),
|
||||
text, EnumSmsChannel.ALIYUN.getName()));
|
||||
}
|
||||
|
||||
if (monitorMobilePropertiesConfig.getDingTalk().getEnabled()) {
|
||||
log.info("开始钉钉通知,内容:{}", text);
|
||||
rabbitTemplate.convertAndSend(MqQueueConstant.DINGTALK_SERVICE_STATUS_CHANGE, text);
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
log.info("Application {} ({}) {}", event.getApplication().getName(),
|
||||
event.getApplication().getId(), event.getType());
|
Loading…
Reference in New Issue