Commit 9f2991b7 authored by 黎博's avatar 黎博

新增金融/电商线上问题统计

parent e61def03
...@@ -46,7 +46,7 @@ public class JiraController { ...@@ -46,7 +46,7 @@ public class JiraController {
WebhookService webhookService; WebhookService webhookService;
/** /**
* jira webhook * jira webhook, 给测试环境提BUG用
* @param request * @param request
*/ */
@PostMapping("/webhook") @PostMapping("/webhook")
...@@ -59,12 +59,16 @@ public class JiraController { ...@@ -59,12 +59,16 @@ public class JiraController {
jiraData.append(str); jiraData.append(str);
} }
br.close(); br.close();
dingRobotService.sendMsgToDing(String.valueOf(jiraData)); webhookService.handleTestJiraBugCommit(String.valueOf(jiraData));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
/**
* jira webhook,给生产俩项目提BUG使用
* @param request
*/
@PostMapping("/prod/webhook") @PostMapping("/prod/webhook")
public void prodWebhook(HttpServletRequest request) { public void prodWebhook(HttpServletRequest request) {
try { try {
......
...@@ -5,5 +5,4 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -5,5 +5,4 @@ import com.baomidou.mybatisplus.extension.service.IService;
public interface DingRobotService extends IService<DingRobot> { public interface DingRobotService extends IService<DingRobot> {
Boolean sendMsgToDing(String jiraData);
} }
...@@ -7,4 +7,10 @@ public interface WebhookService { ...@@ -7,4 +7,10 @@ public interface WebhookService {
* @param jiraData * @param jiraData
*/ */
void handleProdJiraBugUpdate(String jiraData); void handleProdJiraBugUpdate(String jiraData);
/**
* 处理测试环境jira bug 提交
* @param jiraData
*/
Boolean handleTestJiraBugCommit(String jiraData);
} }
...@@ -16,64 +16,6 @@ import org.springframework.stereotype.Service; ...@@ -16,64 +16,6 @@ import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Service @Service
@Slf4j
public class DingRobotServiceImpl extends ServiceImpl<DingRobotMapper, DingRobot> implements DingRobotService { public class DingRobotServiceImpl extends ServiceImpl<DingRobotMapper, DingRobot> implements DingRobotService {
@Autowired
DingRobotMapper dingRobotMapper;
@Autowired
JiraBugPoolService jiraBugPoolService;
@Override
public Boolean sendMsgToDing(String jiraData) {
log.info("收到jira bug提交:{}", jiraData);
String webhookEvent = JsonPath.read(jiraData, "$.webhookEvent");
if (StringUtils.equals(webhookEvent, "jira:issue_created")) {
String creator = JsonPath.read(jiraData, "$.issue.fields.creator.displayName");
String assignee = "";
if (JsonPath.read(jiraData, "$.issue.fields.assignee") == null) {
assignee = "未分配";
} else {
assignee = JsonPath.read(jiraData, "$.issue.fields.assignee.displayName");
}
String key = JsonPath.read(jiraData, "$.issue.key");
String summary = JsonPath.read(jiraData, "$.issue.fields.summary");
String priority = JsonPath.read(jiraData, "$.issue.fields.priority.name");
String module = JsonPath.read(jiraData, "$.issue.fields.components[0].name");
String robotUrl = null;
Integer dingRobotId = null;
Integer status = null;
List<DingRobot> dingRobots = dingRobotMapper.selectList(null);
for (DingRobot dingRobot : dingRobots) {
String projectName = "【" + dingRobot.getProjectName() + "】";
if (summary.contains(projectName)) {
robotUrl = dingRobot.getDingUrl();
dingRobotId = dingRobot.getId();
status = dingRobot.getStatus();
break;
}
}
// 只有创建了dingRobot的项目的BUG才会被放到BUG池子里
if (robotUrl != null && dingRobotId != null) {
// 首次提交的BUG放入bug池子
JiraBugPool jiraBugPool = new JiraBugPool();
jiraBugPool.setKey(key);
jiraBugPool.setSummary(summary);
jiraBugPool.setPriority(priority);
jiraBugPool.setReporter(creator);
jiraBugPool.setAssignee(assignee);
jiraBugPool.setUrl("http://jira2.quantgroup.cn/browse/" + key);
jiraBugPool.setDingUrl(robotUrl);
jiraBugPool.setDingRobotId(dingRobotId);
jiraBugPoolService.save(jiraBugPool);
}
// 只有项目是进行中才会发送通知
if (robotUrl != null && status == 1) {
String markdownMsg = DingdingUtils.buildBugCommitMarkdownMsg(key, summary, creator, assignee, priority, module);
return DingdingUtils.sendToDingding(markdownMsg, robotUrl);
}
}
return false;
}
} }
package cn.qg.holmes.service.quality.impl; package cn.qg.holmes.service.quality.impl;
import cn.qg.holmes.entity.quality.DingRobot;
import cn.qg.holmes.entity.quality.JiraBugPool;
import cn.qg.holmes.mapper.quality.DingRobotMapper;
import cn.qg.holmes.service.quality.JiraBugPoolService;
import cn.qg.holmes.service.quality.WebhookService; import cn.qg.holmes.service.quality.WebhookService;
import cn.qg.holmes.utils.DingdingUtils; import cn.qg.holmes.utils.DingdingUtils;
import com.jayway.jsonpath.JsonPath; import com.jayway.jsonpath.JsonPath;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@Slf4j
@Service @Service
public class WebhookServiceImpl implements WebhookService { public class WebhookServiceImpl implements WebhookService {
@Autowired
DingRobotMapper dingRobotMapper;
@Autowired
JiraBugPoolService jiraBugPoolService;
/**
* 电商线上故障处理群钉钉机器人地址
*/
@Value("${ds.prod.ding.url}")
private String dsProdDingUrl;
/**
* 金融线上故障处理群钉钉机器人地址
*/
@Value("${jr.prod.ding.url}")
private String jrProdDingUrl;
/**
* 处理线上jira bug状态变化
* @param jiraData
*/
@Override @Override
public void handleProdJiraBugUpdate(String jiraData) { public void handleProdJiraBugUpdate(String jiraData) {
// 暂时为了测试 String webhook = "";
String webhook = "https://oapi.dingtalk.com/robot/send?access_token=be220b4bd17f311d70365a0ee81a659b54f06d52f1ee8d4d7d1051a183a266e1";
String webhookEvent = JsonPath.read(jiraData, "$.webhookEvent"); String webhookEvent = JsonPath.read(jiraData, "$.webhookEvent");
String eventTypeName = JsonPath.read(jiraData, "$.issue_event_type_name"); String eventTypeName = JsonPath.read(jiraData, "$.issue_event_type_name");
String creator = JsonPath.read(jiraData, "$.issue.fields.creator.displayName"); String creator = JsonPath.read(jiraData, "$.issue.fields.creator.displayName");
...@@ -29,11 +58,12 @@ public class WebhookServiceImpl implements WebhookService { ...@@ -29,11 +58,12 @@ public class WebhookServiceImpl implements WebhookService {
String priority = JsonPath.read(jiraData, "$.issue.fields.priority.name"); String priority = JsonPath.read(jiraData, "$.issue.fields.priority.name");
String description = JsonPath.read(jiraData, "$.issue.fields.description"); String description = JsonPath.read(jiraData, "$.issue.fields.description");
List<String> attachmentList = JsonPath.read(jiraData, "$.issue.fields.attachment[*].content"); List<String> attachmentList = JsonPath.read(jiraData, "$.issue.fields.attachment[*].content");
// TODO: 2022/2/14
if (StringUtils.equals(key.split("-")[0], "YFGDZZ")) { if (StringUtils.equals(key.split("-")[0], "YFGDZZ")) {
// webhook赋值为金融群的机器人地址 // webhook赋值为金融群的机器人地址
webhook = jrProdDingUrl;
} else if (StringUtils.equals(key.split("-")[0], "YXMXS")) { } else if (StringUtils.equals(key.split("-")[0], "YXMXS")) {
// webhook赋值为电商群的机器人地址 // webhook赋值为电商群的机器人地址
webhook = dsProdDingUrl;
} }
// BUG创建的时候发送通知 // BUG创建的时候发送通知
if (StringUtils.equals(webhookEvent, "jira:issue_created")) { if (StringUtils.equals(webhookEvent, "jira:issue_created")) {
...@@ -114,4 +144,60 @@ public class WebhookServiceImpl implements WebhookService { ...@@ -114,4 +144,60 @@ public class WebhookServiceImpl implements WebhookService {
} }
} }
} }
/**
* 处理测试环境jira bug 提交
* @param jiraData
*/
@Override
public Boolean handleTestJiraBugCommit(String jiraData) {
log.info("收到jira bug提交:{}", jiraData);
String webhookEvent = JsonPath.read(jiraData, "$.webhookEvent");
if (StringUtils.equals(webhookEvent, "jira:issue_created")) {
String creator = JsonPath.read(jiraData, "$.issue.fields.creator.displayName");
String assignee = "";
if (JsonPath.read(jiraData, "$.issue.fields.assignee") == null) {
assignee = "未分配";
} else {
assignee = JsonPath.read(jiraData, "$.issue.fields.assignee.displayName");
}
String key = JsonPath.read(jiraData, "$.issue.key");
String summary = JsonPath.read(jiraData, "$.issue.fields.summary");
String priority = JsonPath.read(jiraData, "$.issue.fields.priority.name");
String module = JsonPath.read(jiraData, "$.issue.fields.components[0].name");
String robotUrl = null;
Integer dingRobotId = null;
Integer status = null;
List<DingRobot> dingRobots = dingRobotMapper.selectList(null);
for (DingRobot dingRobot : dingRobots) {
String projectName = "【" + dingRobot.getProjectName() + "】";
if (summary.contains(projectName)) {
robotUrl = dingRobot.getDingUrl();
dingRobotId = dingRobot.getId();
status = dingRobot.getStatus();
break;
}
}
// 只有创建了dingRobot的项目的BUG才会被放到BUG池子里
if (robotUrl != null && dingRobotId != null) {
// 首次提交的BUG放入bug池子
JiraBugPool jiraBugPool = new JiraBugPool();
jiraBugPool.setKey(key);
jiraBugPool.setSummary(summary);
jiraBugPool.setPriority(priority);
jiraBugPool.setReporter(creator);
jiraBugPool.setAssignee(assignee);
jiraBugPool.setUrl("http://jira2.quantgroup.cn/browse/" + key);
jiraBugPool.setDingUrl(robotUrl);
jiraBugPool.setDingRobotId(dingRobotId);
jiraBugPoolService.save(jiraBugPool);
}
// 只有项目是进行中才会发送通知
if (robotUrl != null && status == 1) {
String markdownMsg = DingdingUtils.buildBugCommitMarkdownMsg(key, summary, creator, assignee, priority, module);
return DingdingUtils.sendToDingding(markdownMsg, robotUrl);
}
}
return false;
}
} }
...@@ -6,6 +6,7 @@ import cn.qg.holmes.service.quality.DingRobotService; ...@@ -6,6 +6,7 @@ import cn.qg.holmes.service.quality.DingRobotService;
import cn.qg.holmes.service.quality.JiraBugPoolService; import cn.qg.holmes.service.quality.JiraBugPoolService;
import cn.qg.holmes.service.quality.JiraService; import cn.qg.holmes.service.quality.JiraService;
import cn.qg.holmes.utils.DingdingUtils; import cn.qg.holmes.utils.DingdingUtils;
import com.alibaba.fastjson.JSON;
import com.atlassian.jira.rest.client.api.domain.Issue; import com.atlassian.jira.rest.client.api.domain.Issue;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -40,6 +41,18 @@ public class BugNotifyTask { ...@@ -40,6 +41,18 @@ public class BugNotifyTask {
@Value("${task.debug}") @Value("${task.debug}")
private String taskDebug; private String taskDebug;
/**
* 电商线上故障处理群钉钉机器人地址
*/
@Value("${ds.prod.ding.url}")
private String dsProdDingUrl;
/**
* 金融线上故障处理群钉钉机器人地址
*/
@Value("${jr.prod.ding.url}")
private String jrProdDingUrl;
/** /**
* 数据工单bug统计 * 数据工单bug统计
* @throws Exception * @throws Exception
...@@ -156,4 +169,19 @@ public class BugNotifyTask { ...@@ -156,4 +169,19 @@ public class BugNotifyTask {
} }
} }
} }
/**
* 电商和金融线上工单每天提醒
* @throws Exception
*/
// @Scheduled(cron = "0 */1 * * * ?")
@Scheduled(cron = "0 0 18 ? * *")
public void prodBugDailyNotifyTask() throws Exception {
if (taskDebug.equals("true")) {
Iterable<Issue> dsUnsolvedList = jiraService.getIssueListByJQL("project = YXMXS AND resolution = Unresolved ORDER BY priority DESC, created DESC");
Iterable<Issue> jrUnsolvedList = jiraService.getIssueListByJQL("project = YFGDZZ AND resolution = Unresolved ORDER BY priority DESC, created DESC");
DingdingUtils.sendToDingding(DingdingUtils.buildDailyProdBugNotifyMsg(dsUnsolvedList), dsProdDingUrl);
DingdingUtils.sendToDingding(DingdingUtils.buildDailyProdBugNotifyMsg(jrUnsolvedList), jrProdDingUrl);
}
}
} }
...@@ -279,6 +279,37 @@ public class DingdingUtils { ...@@ -279,6 +279,37 @@ public class DingdingUtils {
return buildMarkdownMsg(title, content, true); return buildMarkdownMsg(title, content, true);
} }
/**
* 构建每日线上未解决工单统计
* @param issues jira bug 列表
* @return
*/
public static String buildDailyProdBugNotifyMsg(Iterable<Issue> issues) {
String title = "线上未解决工单统计";
String content = "📣线上未解决工单统计:" + "\n\n";
int count = 0;
for (Issue issue: issues) {
count = count + 1;
String issueUrl = "http://jira2.quantgroup.cn/browse/" + issue.getKey();
content = content + count + "、[" + issue.getSummary().replace("\"", "") + "](" + issueUrl + ")\n";
content = content + "- 优先级:" + issue.getPriority().getName() + "\n";
content = content + "- 状态:" + issue.getStatus().getName() + "\n";
String assignee = "";
if (issue.getAssignee() == null) {
assignee = "未分配";
} else {
assignee = issue.getAssignee().getDisplayName();
}
content = content + "- 经办人:" + assignee + "\n";
DateTime startDate = issue.getCreationDate();
DateTime curDate = new DateTime();
int duration = calculateBugFixTime(startDate, curDate);
content += "- 持续时间:" + duration + "小时\n\n";
}
content += "**截止当前,共有" + String.valueOf(count) + "个工单未解决,请对应经办人尽快跟进解决**";
return buildMarkdownMsg(title, content, true);
}
/** /**
* 计算BUG持续时间 * 计算BUG持续时间
* @param startDate 开始日期 * @param startDate 开始日期
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment