(四)Jira Api连接:缺点剖析和任务分析

        迭代更新开展期内或是完毕后,在大家的检测日报或是检测报告中必须反映缺点具体情况,乃至大伙儿工作效能状况。文中就探讨下怎样根据jira api获得缺点信息内容并开展剖析,另外获得要求子每日任务状况来掌握检测和开发设计的施工时间。

  实际编码以下

 //定义数组目标
 @Data
public class ReportData {

    String name;

    int bugNum;

    int taskNum;

    double taskTime;

    String bugTate;
}
 /**
     * 获得sprint下的开发设计每日任务、测试任务及其缺点
     *
     * @param springId
     * @return
     */
    public static Map<String, Map<String, ReportData>> getReportData(String springId) {

        Map<String, Map<String, ReportData>> result = new HashMap<>();
        //缺点比较多时大家开展分页查询,默认设置一页150条数据信息
        JSONObject jsonObject = getIssueKey(0, springId);
        if (!JSONNull.getInstance().equals(jsonObject)) {

            //分析查看的数据信息
            Map<String, ReportData> testerData = new HashMap<>();//测试任务
            Map<String, ReportData> developData = new HashMap<>();//开发设计每日任务
            Map<String, ReportData> bugDetail = new HashMap<>();//缺陷等级
            Map<String, ReportData> bugReason = new HashMap<>();//缺点缘故
           //分析数据信息
            result = getReportData(jsonObject, testerData, developData, bugDetail, bugReason);
            //获得插口回到的缺点数量
            int total = jsonObject.getInt("total");
            logger.info("spring上一共有story"   total   "个");
            if (total > 150) {
               //假如超过150则开展分页查询
                int page = total / 150;
                if (total % 150 > 0) {
                    page = page   1;//总页数
                }
                logger.info("spring上一共有story"   page   "页");
                for (int pageIndex = 1; pageIndex < page; pageIndex  ) {

                    //分页查询读取数据
                    JSONObject object = getIssueKey(pageIndex * 150, springId);
                    if (!JSONNull.getInstance().equals(object)) {

                        //分析数据信息
                        result = getReportData(object, result.get("testerGeneral"), result.get("developGeneral"), result.get("bugDetail"), result.get("bugReason"));
                    }
                }
            }
        }
        return result;
    }
     /**
     * 获得spring下的issue
     *
     * @param startAt
     * @param springId
     * @return
     */
    private static JSONObject getIssueKey(int startAt, String springId) {
        //启用jira API接口获得sprint下全部issue
        HttpClientResponse issueResponse = httpClient("get", "http://you jira address:port/rest/agile/1.0/sprint/"   springId   "/issue?maxResults=150&startAt="   startAt, "");
        if (issueResponse != null && "200".equals(issueResponse.getStateCode())
                && issueResponse.getResponseBody() != null) {
           //立即回到查看結果
            JSONObject jsonObject = JSONObject.fromObject(issueResponse.getResponseBody().toString());
            return jsonObject;
        }

        return null;
    }
   /**
     * 分析数据信息 各自分析出测试工程师状况,开发者状况,缺陷等级概述及其缺点缘故概述
     *
     * @param jsonObject
     * @param testerData
     * @param developData
     * @param bugDetail
     * @param bugReason
     * @return
     */
    private static Map<String, Map<String, ReportData>> getReportData(JSONObject jsonObject, Map<String, ReportData> testerData, Map<String, ReportData> developData, Map<String, ReportData> bugDetail, Map<String, ReportData> bugReason) {

        Map<String, Map<String, ReportData>> result = new HashMap<>();
        JSONArray issueArray = jsonObject.getJSONArray("issues");
        if (issueArray != null && issueArray.size() > 0) {
            for (int i = 0; i < issueArray.size(); i  ) {

                JSONObject issueObject = issueArray.getJSONObject(i);
                JSONObject fields = issueObject.getJSONObject("fields");
                if (!JSONNull.getInstance().equals(fields)) {  //获得issuetype
                    JSONObject issuetype = fields.getJSONObject("issuetype");
                    if (!JSONNull.getInstance().equals(issuetype)) {
                        //获得issue 类型
                        String issuetypeName = issuetype.getString("name");
                        //获得经办人员信息内容
                        JSONObject assignee = fields.getJSONObject("assignee");
                        if (!JSONNull.getInstance().equals(assignee)) {
                            //获得经办人员好听的花名
                            String displayName = assignee.getString("displayName");
                            //获得达到目标的预计時间的信息内容,这一字段名是自定字段名
                            double originalEstimate = 0;
                            JSONObject timetracking = fields.getJSONObject("timetracking");
                            if (!JSONNull.getInstance().equals(timetracking) && timetracking.size() > 0) {
                                //获得预计時间
                                originalEstimate = timetracking.getInt("originalEstimateSeconds") / 3600;
                            }                           
                          //依据每日任务类型开展不一样的解决
                            switch (issuetypeName) {
                                case "Story"://要求
                                    break;
                                case "SubTask"://开发设计子每日任务
                                   setReportData(developData, displayName, originalEstimate, false);
                                    break;
                                case "检测子每日任务":检测子每日任务
                                    setReportData(testerData, displayName, originalEstimate, false);
                                    break;
                                case "缺点":
                                   //获得处理結果
                                    JSONObject resolution = fields.getJSONObject("resolution");
                                    if (!JSONNull.getInstance().equals(resolution)) {
                                        //过虑掉被否定的bug
                                        if ("被否定".equals(resolution.getString("name"))) {
                                            break;
                                        }
                                    }
                                    setReportData(developData, displayName, 0, true);
                                    //获得汇报人信息内容
                                    JSONObject reporter = fields.getJSONObject("reporter");
                                    if (!JSONNull.getInstance().equals(reporter)) {
                                        //获得汇报人好听的花名
                                        String reporterName = reporter.getString("displayName");
                                        setReportData(testerData, reporterName, 0, true);
                                    }
                                    //bug级别开展归类
                                    JSONObject priority = fields.getJSONObject("priority");
                                    setReportData(bugDetail, priority, "name");
                                    //bug缘故开展归类
                                    JSONObject reason = fields.getJSONObject("customfield_11522");
                                    setReportData(bugReason, reason, "value");
                                default:
                                    break;
                            }
                        }
                    }
                }
            }
        }

        result.put("testerGeneral", testerData);
        result.put("developGeneral", developData);
        result.put("bugDetail", bugDetail);
        result.put("bugReason", bugReason);
        return result;
    }  
    /**
     * 统一设定汇报信息内容
     *
     * @param reportDataMap
     * @param key
     * @param originalEstimate
     * @param isBug
     */
    private static void setReportData(Map<String, ReportData> reportDataMap, String key, double originalEstimate, boolean isBug) {

        DecimalFormat decimalFormat = new DecimalFormat("0.00");
        if (reportDataMap.containsKey(key)) {
            //假如包括key
            ReportData temp = reportDataMap.get(key);
            if (originalEstimate != 0) {
                //设定任务时间,以小时计算
                temp.setTaskTime(temp.getTaskTime()   originalEstimate);
            }
            if (isBug) {
                //缺点总数 1
                temp.setBugNum(temp.getBugNum()   1);
            } else {
                //每日任务总数 1
                temp.setTaskNum(temp.getTaskNum()   1);
            }
            //设定不合格率
            String formatNum = decimalFormat
                    .format((float) temp.getBugNum()
                            / (temp.getTaskTime() == 0 ? 1 : temp.getTaskTime()) * 100);
            temp.setBugTate(formatNum   "%");
        } else {
            ReportData reportData = new ReportData();
            if (originalEstimate != 0) {
                //设定任务时间,以小时计算
                reportData.setTaskTime(originalEstimate);
            }
            if (isBug) {
                //缺点总数 1
                reportData.setBugNum(1);
            } else {
                //每日任务总数 1
                reportData.setTaskNum(1);
            }
            //设定不合格率
            String formatNum = decimalFormat
                    .format((float) reportData.getBugNum()
                            / (reportData.getTaskTime() == 0 ? 1 : reportData.getTaskTime()) * 100);
            reportData.setBugTate(formatNum   "%");
            reportData.setName(key);
            reportDataMap.put(key, reportData);
        }
    }

    /**
     * 统一设定汇报信息内容
     *
     * @param dataMap
     * @param jsonObject
     * @param key
     */
    private static void setReportData(Map<String, ReportData> dataMap, JSONObject jsonObject, String key) {

        if (!JSONNull.getInstance().equals(jsonObject)) {
            //获得key值
            String priorityName = jsonObject.getString(key);
            if (dataMap.containsKey(priorityName)) {
                //总数 1
                ReportData reportData = dataMap.get(priorityName);
                reportData.setBugNum(reportData.getBugNum()   1);
            } else {
                //总数 1
                ReportData reportData = new ReportData();
                reportData.setBugNum(1);
                reportData.setName(priorityName);
                dataMap.put(priorityName, reportData);
            }
        }
    }
//getReportData(String sprintId) 方式 回到結果实例,依照Map载入成自身的文件格式就可以了
{
  bugReason={
    作用不正确=ReportData(name=作用不正确,
    bugNum=3,
    taskNum=0,
    taskTime=0.0,
    bugTate=null),
    要求难题=ReportData(name=要求难题,
    bugNum=1,
    taskNum=0,
    taskTime=0.0,
    bugTate=null)
  },
  developGeneral={
    桑落=ReportData(name=桑落,
    bugNum=3,
    taskNum=7,
    taskTime=28.0,
    bugTate=10.71%),
    白衫=ReportData(name=白衫,
    bugNum=0,
    taskNum=8,
    taskTime=18.0,
    bugTate=0.00%),
    清远市=ReportData(name=清远市,
    bugNum=1,
    taskNum=0,
    taskTime=0.0,
    bugTate=100.00%)
  },
  testerGeneral={
    黄台=ReportData(name=黄台,
    bugNum=4,
    taskNum=3,
    taskTime=24.0,
    bugTate=16.67%)
  },
  bugDetail={
    Medium=ReportData(name=Medium,
    bugNum=4,
    taskNum=0,
    taskTime=0.0,
    bugTate=null)
  }
}
//对結果提升后以标志表明如下图

 

 

 

 

大量文章内容请扫码关注

 

评论(0条)

刀客源码 游客评论