公司最近做大屏幕数据展示,需要获取svn/git、jira、jenkins、sonar上的数据。本人除了git外,其它工具都不熟,索性网络时代救了我,本人也是查了很多资料来实现自己的项目需求功能。
java获取svn代码,是看到了scdn上的一位大神杰作来修改的,由于本人的粗心,那位大神的链接地址一时间找不到了。以后看到了一定补上链接,在这里对大神说声抱歉,以下奉上本人修改后的代码。
大神连接地址https://blog.csdn.net/u012621115/article/details/51851572
1.获取svn数据所依赖的jar

		<!--svn获取数据需要jar-->
		<!-- https://mvnrepository.com/artifact/org.tmatesoft.svnkit/svnkit -->
		<dependency>
			<groupId>org.tmatesoft.svnkit</groupId>
			<artifactId>svnkit</artifactId>
			<version>1.9.3</version>
		</dependency>
		<!--svn获取需要jar完毕-->

2.存入后台版本号、当前版本的总影响行数

package com.zkr.cxhjcxt.dto;

import com.zkr.cxhjcxt.model.SvnDataAuxiliaryTwo;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by youzongxu on 2018/9/7.
 */
@Data
public class SvnDto {
    private int sum;
    private List<SvnDataAuxiliaryTwo> lists = new ArrayList<>();
    private long version;
}

3.存入后台版本号、影响行数、文件路径、文件类型

package com.zkr.cxhjcxt.model;

import lombok.Data;

/**
 * Created by youzongxu on 2018/9/10.
 */
@Data
public class SvnDataAuxiliaryTwo extends BaseEntity<Long>{
    private static final long serialVersionUID = -124865218511677256L;
    private Long svnReversion;
    private Integer svnAddlines;
    private String svnFilepath;
    private String svnChangetype;
}

4.存入后台提交人、版本号、svn信息、提交svn时间

package com.zkr.cxhjcxt.model;

import lombok.Data;

import java.util.Date;

/**
 * Created by youzongxu on 2018/9/7.
 */
@Data
public class SvnData extends BaseEntity<Long>{
    private static final long serialVersionUID = 6041141704397137128L;
    private String author;
    private Long revision;
    private String svnMessage;
    private Date svnTime;
}

5.后台存入数据、借助的都是下面svn工具类中的方法,这里面的有些数据需要改成自己所用到的

package com.zkr.cxhjcxt.utils;

import com.google.common.collect.Lists;
import com.zkr.cxhjcxt.constants.SvnTimeConstants;
import com.zkr.cxhjcxt.dao.DataConfigurationDao;
import com.zkr.cxhjcxt.dict.DictConstants;
import com.zkr.cxhjcxt.dto.SvnDto;
import com.zkr.cxhjcxt.model.DataConfiguration;
import com.zkr.cxhjcxt.model.SvnDataAuxiliaryOne;
import com.zkr.cxhjcxt.model.SvnDataAuxiliaryThree;
import com.zkr.cxhjcxt.service.SvnDataService;
import com.zkr.cxhjcxt.service.SysLogService;
import com.zkr.cxhjcxt.timedutils.svnutil;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 *
 * @author youzongxu
 * @date 2018/9/12
 */
@Slf4j
public class SvnUtil {

    public void SvnUtil(){
        //获取1:请求路径2:账号3:密码
        DataConfigurationDao dataConfigurationDao = SpringUtil.getBean(DataConfigurationDao.class);
        List<DataConfiguration> svnget = dataConfigurationDao.dataGetSvn(DictConstants.SVN_DICT);
        if(null != svnget){
            Date now = new Date();
            SvnDataService svnDataService = SpringUtil.getBean(SvnDataService.class);
            List<SvnDto> lists = Lists.newArrayList();
            int today = 0;
            int sevenToday = 0;
            int thirtyToday = 0;
            int nows = 0;
            int ones = 0;
            int twos = 0;
            int threes = 0;
            int fours = 0;
            int fives = 0;
            int sixs = 0;
            int sevens = 0;
            for (DataConfiguration ls:svnget) {
                Date daysago = new Date(now.getTime()-convertDaysToMilliseconds(Integer.parseInt(ls.getTimeFrame())));
                //启动
                svnutil svn = new svnutil(ls.getDataUsername(),ls.getDataPassword(),ls.getDataUrl());
                try {
                    //主表数据保存
                    List<SvnDto> svnDtos = svn.staticticsCodeAddByTime(now, fm(daysago));
                    lists.addAll(svnDtos);
                    //辅表数保存
                    Map<String, Object> map = svn.commitCount();
                    today += Integer.parseInt(map.get("today").toString());
                    sevenToday += Integer.parseInt(map.get("sevenToday").toString());
                    thirtyToday += Integer.parseInt(map.get("thirtyToday").toString());

                    Map<String, Object> map1 = svn.dmCount();
                    nows += Integer.parseInt(map1.get("now").toString());
                    ones += Integer.parseInt(map1.get("one").toString());
                    twos += Integer.parseInt(map1.get("two").toString());
                    threes += Integer.parseInt(map1.get("three").toString());
                    fours += Integer.parseInt(map1.get("four").toString());
                    fives += Integer.parseInt(map1.get("five").toString());
                    sixs += Integer.parseInt(map1.get("six").toString());
                    sevens += Integer.parseInt(map1.get("seven").toString());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            List<SvnDataAuxiliaryOne> svnDataAuxiliaryOnes = getSvnDataAuxiliaryOnes(today, sevenToday, thirtyToday);
            List<SvnDataAuxiliaryThree> svnDataAuxiliaryThrees = getSvnDataAuxiliaryThrees(nows, ones, twos, threes, fours, fives, sixs, sevens);
            svnDataService.saveData(lists);
            svnDataService.saveCommitCount(svnDataAuxiliaryOnes);
            svnDataService.saveWeekCommitCount(svnDataAuxiliaryThrees);
        }
    }

    private List<SvnDataAuxiliaryThree> getSvnDataAuxiliaryThrees(int nows, int ones, int twos, int threes, int fours, int fives, int sixs, int sevens) {
        List<SvnDataAuxiliaryThree> ls = Lists.newArrayList();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree = new SvnDataAuxiliaryThree();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree1 = new SvnDataAuxiliaryThree();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree2 = new SvnDataAuxiliaryThree();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree3 = new SvnDataAuxiliaryThree();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree4 = new SvnDataAuxiliaryThree();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree5 = new SvnDataAuxiliaryThree();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree6 = new SvnDataAuxiliaryThree();
        SvnDataAuxiliaryThree svnDataAuxiliaryThree7 = new SvnDataAuxiliaryThree();

        svnDataAuxiliaryThree.setName(SvnTimeConstants.Today);
        svnDataAuxiliaryThree.setSum(nows);
        svnDataAuxiliaryThree1.setName(SvnTimeConstants.ONE);
        svnDataAuxiliaryThree1.setSum(ones);
        svnDataAuxiliaryThree2.setName(SvnTimeConstants.TWO);
        svnDataAuxiliaryThree2.setSum(twos);
        svnDataAuxiliaryThree3.setName(SvnTimeConstants.THREE);
        svnDataAuxiliaryThree3.setSum(threes);
        svnDataAuxiliaryThree4.setName(SvnTimeConstants.FOUR);
        svnDataAuxiliaryThree4.setSum(fours);
        svnDataAuxiliaryThree5.setName(SvnTimeConstants.FIVE);
        svnDataAuxiliaryThree5.setSum(fives);
        svnDataAuxiliaryThree6.setName(SvnTimeConstants.SIX);
        svnDataAuxiliaryThree6.setSum(sixs);
        svnDataAuxiliaryThree7.setName(SvnTimeConstants.SEVEN);
        svnDataAuxiliaryThree7.setSum(sevens);

        ls.add(svnDataAuxiliaryThree);
        ls.add(svnDataAuxiliaryThree1);
        ls.add(svnDataAuxiliaryThree2);
        ls.add(svnDataAuxiliaryThree3);
        ls.add(svnDataAuxiliaryThree4);
        ls.add(svnDataAuxiliaryThree5);
        ls.add(svnDataAuxiliaryThree6);
        ls.add(svnDataAuxiliaryThree7);
        return ls;
    }

    private List<SvnDataAuxiliaryOne> getSvnDataAuxiliaryOnes(int today, int sevenToday, int thirtyToday){
        List<SvnDataAuxiliaryOne> ls = Lists.newArrayList();
        SvnDataAuxiliaryOne svnDataAuxiliaryOne = new SvnDataAuxiliaryOne();
        svnDataAuxiliaryOne.setName(SvnTimeConstants.Today);
        svnDataAuxiliaryOne.setSum(today);
        SvnDataAuxiliaryOne svnDataAuxiliaryOne1 = new SvnDataAuxiliaryOne();
        svnDataAuxiliaryOne1.setName(SvnTimeConstants.Nearlysevendays);
        svnDataAuxiliaryOne1.setSum(sevenToday);
        SvnDataAuxiliaryOne svnDataAuxiliaryOne2 = new SvnDataAuxiliaryOne();
        svnDataAuxiliaryOne2.setName(SvnTimeConstants.NearlyThirtydays);
        svnDataAuxiliaryOne2.setSum(thirtyToday);
        ls.add(svnDataAuxiliaryOne);
        ls.add(svnDataAuxiliaryOne1);
        ls.add(svnDataAuxiliaryOne2);
        return ls;
    }

    public long convertDaysToMilliseconds (int days){
        return 1000L*3600*24*days;
    }

    public Date fm(Date daysago){
        try {
            SimpleDateFormat sdf=new SimpleDateFormat(SvnTimeConstants.fm);
            Date parse = sdf.parse(sdf.format(daysago));
            return parse;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return daysago;
    }
}

6.svn工具类、需要把userName 、password 、urlString 更换称自己的、我是直接从后台数据库中获取的,自己可以写个main方法测试下。

package com.zkr.cxhjcxt.timedutils;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.zkr.cxhjcxt.constants.SvnTimeConstants;
import com.zkr.cxhjcxt.dto.ChangeFile;
import com.zkr.cxhjcxt.dto.SvnDto;
import com.zkr.cxhjcxt.model.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.util.CollectionUtils;
import org.tmatesoft.svn.core.*;
import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager;
import org.tmatesoft.svn.core.internal.wc.DefaultSVNOptions;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.io.SVNRepositoryFactory;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

import java.io.*;
import java.util.*;

/**
 * svn获取
 *
 * @author youzongxu
 * @date 2018/9/7
 */
@Slf4j
public class svnutil {
    private String userName = "";
    private String password = "";
    private String urlString = "";
    /**
     * 临时文件
     */
    private String tempDir = System.getProperty("java.io.tmpdir");
    private DefaultSVNOptions options = SVNWCUtil.createDefaultOptions(true);
    private Random random = new Random();

    private SVNRepository repos;
    private ISVNAuthenticationManager authManager;

    public svnutil(String u,String p,String url) {
        try {
            userName = u;
            password = p;
            urlString = url;
            init();
        } catch (SVNException e) {
            e.printStackTrace();
        }
    }

    public void init() throws SVNException{
        log.info("开始加载");
        authManager = SVNWCUtil.createDefaultAuthenticationManager(new File(tempDir+"/auth"), userName, password.toCharArray());
        options.setDiffCommand("-x -w");
        repos = SVNRepositoryFactory.create(SVNURL
                .parseURIEncoded(urlString));
        repos.setAuthenticationManager(authManager);
        log.info("init completed");
    }

    /**
     * 统计一段时间内代码增加量
     * @param st
     * @param et
     * @return
     * @throws Exception
     */
    public List<SvnDto> staticticsCodeAddByTime(Date st, Date et) throws Exception{
        SVNLogEntry[] logs = getLogByTime(st, et);
        List<SvnDto> ls = Lists.newArrayList();
        if(logs.length > 0){
            for(SVNLogEntry log:logs){
                File logFile = getChangeLog(log.getRevision(), log.getRevision()-1);
                SvnDto svnDto = new SvnDto();
                svnDto.setAuthor(log.getAuthor());
                svnDto.setRevision(log.getRevision());
                svnDto.setSvnMessage(StringUtils.isNotBlank(log.getMessage())?log.getMessage():SvnTimeConstants.SvnMessageFlag);
                svnDto.setSvnTime(log.getDate());
                ls.add(svnDto);
                List<SvnDataAuxiliaryFour> fourList = getChangeFileList(log.getRevision());
                List<SvnDataAuxiliaryTwo> twoList = staticticsCodeAdd(logFile, log.getRevision());
                if(!CollectionUtils.isEmpty(fourList)){
                    svnDto.setFourList(fourList);
                }
                if(!CollectionUtils.isEmpty(twoList)){
                    svnDto.setTwoList(twoList);
                }
            }
        }
        return ls;
    }

    /**获取某一版本有变动的文件路径
     * @param version
     * @return
     * @throws SVNException
     */
    public List<SvnDataAuxiliaryFour> getChangeFileList(long version) throws SVNException{
        List<SvnDataAuxiliaryFour> ls = Lists.newArrayList();
        SVNLogClient logClient = new SVNLogClient( authManager, options );
        SVNURL url = SVNURL.parseURIEncoded(urlString);
        String[] paths = { "." };
        SVNRevision pegRevision = SVNRevision.create( version );
        SVNRevision startRevision = SVNRevision.create( version );
        SVNRevision endRevision = SVNRevision.create( version );
        long limit = 9999L;
        ISVNLogEntryHandler handler = new ISVNLogEntryHandler() {
            /**
             * This method will process when doLog() is done
             */
            @Override
            public void handleLogEntry( SVNLogEntry logEntry ) {
                Map<String, SVNLogEntryPath> maps = logEntry.getChangedPaths();
                Set<Map.Entry<String, SVNLogEntryPath>> entries = maps.entrySet();
                for(Map.Entry<String, SVNLogEntryPath> entry : entries){
                    SvnDataAuxiliaryFour svnDataAuxiliaryFour = new SvnDataAuxiliaryFour();
                    svnDataAuxiliaryFour.setSvnVersion(logEntry.getRevision());
                    svnDataAuxiliaryFour.setSvnPath(entry.getValue().getPath());
                    svnDataAuxiliaryFour.setSvnType(String.valueOf(entry.getValue().getType()));
                    ls.add(svnDataAuxiliaryFour);
                }
            }
        };
        try {
            logClient.doLog( url, paths, pegRevision, startRevision, endRevision, false, true, limit, handler );
        }
        catch ( SVNException e ) {
            System.out.println( "Error in doLog() " );
            e.printStackTrace();
        }
        return ls;
    }

    /**获取一段时间内,所有的commit记录
     * @param st	开始时间
     * @param et	结束时间
     * @return
     * @throws SVNException
     */
    public SVNLogEntry[] getLogByTime(Date st, Date et) throws SVNException{
        long startRevision = repos.getDatedRevision(st);
        long endRevision = repos.getDatedRevision(et);
        @SuppressWarnings("unchecked")
        Collection<SVNLogEntry> logEntries = repos.log(new String[]{""}, null,
                startRevision, endRevision, true, true);
        SVNLogEntry[] svnLogEntries = logEntries.toArray(new SVNLogEntry[0]);
        SVNLogEntry[] svnLogEntries1 = Arrays.copyOf(svnLogEntries, svnLogEntries.length - 1);
        return svnLogEntries1;
    }


    /**获取版本比较日志,并存入临时文件
     * @param startVersion
     * @param endVersion
     * @return
     */
    public File getChangeLog(long startVersion, long endVersion) {
        SVNDiffClient diffClient = new SVNDiffClient(authManager, options);
        diffClient.setGitDiffFormat(true);
        File tempLogFile;
        OutputStream outputStream = null;
        String svnDiffFile;
        do {
            svnDiffFile = tempDir + "/svn_diff_file_"+startVersion+"_"+endVersion+"_"+random.nextInt(10000)+".txt";
            tempLogFile = new File(svnDiffFile);
        } while (tempLogFile != null && tempLogFile.exists());
        try {
            tempLogFile.createNewFile();
            outputStream = new FileOutputStream(svnDiffFile);
            diffClient.doDiff(SVNURL.parseURIEncoded(urlString),
                    SVNRevision.create(startVersion),
                    SVNURL.parseURIEncoded(urlString),
                    SVNRevision.create(endVersion),
                    SVNDepth.UNKNOWN, true, outputStream);
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(outputStream!=null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return tempLogFile;
    }

    /**分析变更的代码,统计代码增量
     * @param file
     * @param revision
     * @return
     * @throws Exception
     */
    public List<SvnDataAuxiliaryTwo> staticticsCodeAdd(File file, long revision) throws Exception{
        log.info("开始统计修改代码行数");
        List<SvnDataAuxiliaryTwo> twoList = Lists.newArrayList();
        FileReader fileReader = new FileReader(file);
        BufferedReader in = new BufferedReader(fileReader);
        String line;
        StringBuffer buffer = new StringBuffer(1024);
        boolean start = false;
        while((line=in.readLine()) != null){
            if(line.startsWith("Index:")){
                if(start){
                    ChangeFile changeFile = parseChangeFile(buffer);
                    if(null!=changeFile){
                        String filePath = changeFile.getFilePath();
                        if(getBoolean(filePath)){
                            int oneSize = staticOneFileChange(changeFile);
                            SvnDataAuxiliaryTwo svnDataAuxiliaryTwo = new SvnDataAuxiliaryTwo();
                            svnDataAuxiliaryTwo.setSvnAddlines(oneSize);
                            svnDataAuxiliaryTwo.setSvnFilepath("/"+changeFile.getFilePath());
                            svnDataAuxiliaryTwo.setSvnReversion(revision);
                            twoList.add(svnDataAuxiliaryTwo);
                        }
                    }
                    buffer.setLength(0);
                }
                start = true;
            }
            buffer.append(line).append('\n');
        }
        if(buffer.length() > 0){
            ChangeFile changeFile = parseChangeFile(buffer);
            if(null!=changeFile){
                String filePath = changeFile.getFilePath();
                if(getBoolean(filePath)){
                    int oneSize = staticOneFileChange(changeFile);
                    SvnDataAuxiliaryTwo svnDataAuxiliaryTwo = new SvnDataAuxiliaryTwo();
                    svnDataAuxiliaryTwo.setSvnAddlines(oneSize);
                    svnDataAuxiliaryTwo.setSvnFilepath("/"+changeFile.getFilePath());
                    svnDataAuxiliaryTwo.setSvnReversion(revision);
                    twoList.add(svnDataAuxiliaryTwo);
                }
            }
        }
        in.close();
        fileReader.close();
        boolean deleteFile = file.delete();
        log.info("-----delete file-----"+deleteFile);
        return twoList;
    }

    public boolean getBoolean(String filePath){
        String[] k = {".java", ".html", ".css", ".js", ".jsp", ".properties",".xml",".json",".sql",".wxml",".wxss"};
        List<String> strings = Arrays.asList(k);
        boolean ba = false;
        c:for (String ls:strings) {
            if(filePath.contains(ls)){
                ba = true;
                break c;
            }
        }
        return ba;
    }

    /**统计单个文件的增加行数,(先通过过滤器,如文件后缀、文件路径等等),也可根据修改类型来统计等,这里只统计增加或者修改的文件
     * @param changeFile
     * @return
     */
    public int staticOneFileChange(ChangeFile changeFile){
        char changeType = changeFile.getChangeType();
        char A = 'A';
        char M = 'M';
        if(A == changeType){
            return countAddLine(changeFile.getFileContent());
        }else if(M == changeType){
            return countAddLine(changeFile.getFileContent());
        }
        return 0;
    }

    /**解析单个文件变更日志:A表示增加文件,M表示修改文件,D表示删除文件,U表示末知
     * @param str
     * @return
     */
    public ChangeFile parseChangeFile(StringBuffer str){
        int index = str.indexOf("\n@@");
        if(index > 0){
            String header = str.substring(0, index);
            String[] headers = header.split("\n");
            String filePath = "";
            if(StringUtils.isNotBlank(headers[0])){
                filePath = headers[0].substring(7);
            }
            char changeType = 'U';
            boolean oldExist = !headers[2].endsWith("(nonexistent)");
            boolean newExist = !headers[3].endsWith("(nonexistent)");
            if(oldExist && !newExist){
                changeType = 'D';
            }else if(!oldExist && newExist){
                changeType = 'A';
            }else if(oldExist && newExist){
                changeType = 'M';
            }
            int bodyIndex = str.indexOf("@@\n")+3;
            String body = str.substring(bodyIndex);
            if(StringUtils.isNotBlank(filePath)){
                ChangeFile changeFile = new ChangeFile(filePath, changeType, body);
                return changeFile;
            }
        }else{
            String[] headers = str.toString().split("\n");
            log.info("headers"+headers[0]);
            if(StringUtils.isNotBlank(headers[0])){
                String filePath = headers[0].substring(7);
                ChangeFile changeFile = new ChangeFile(filePath, 'U', null);
                return changeFile;
            }
        }
        return null;
    }


    /**通过比较日志,统计以+号开头的非空行
     * @param content
     * @return
     */
    public int countAddLine(String content){
        int sum = 0;
        if(content !=null){
            content = '\n' + content +'\n';
            char[] chars = content.toCharArray();
            int len = chars.length;
            //判断当前行是否以+号开头
            boolean startPlus = false;
            //判断当前行,是否为空行(忽略第一个字符为加号)
            boolean notSpace = false;
            for(int i=0;i<len;i++){
                char ch = chars[i];
                if(ch =='\n'){
                    //当当前行是+号开头,同时其它字符都不为空,则行数+1
                    if(startPlus && notSpace){
                        sum++;
                        notSpace = false;
                    }
                    //为下一行做准备,判断下一行是否以+头
                    if(i < len-1 && chars[i+1] == '+'){
                        startPlus = true;
                        //跳过下一个字符判断,因为已经判断了
                        i++;
                    }else{
                        startPlus = false;
                    }
                }else if(startPlus && ch > ' '){
                    //如果当前行以+开头才进行非空行判断
                    notSpace = true;
                }
            }
        }
        return sum;
    }


    /**
     * 获取提交次数
     * @param dt
     * @return
     */
    public int countSum(Date dt){
        try {
            Date now = new Date();
            SVNLogEntry[] logByTime = getLogByTime(now, dt);
            List<SVNLogEntry> svnLogEntries = Arrays.asList(logByTime);
            return svnLogEntries.size();
        } catch (SVNException e) {
            return 0;
        }
    }

    /**
     * 获取提交量
     * @param dt
     * @return
     */
    public int dmCountSum(Date dt){
        int sum = 0;
        try {
            Date now = new Date();
            SVNLogEntry[] logByTime = getLogByTime(now, dt);
            List<SVNLogEntry> svnLogEntries = Arrays.asList(logByTime);
            sum = 0;
            for (SVNLogEntry ls:svnLogEntries) {
                sum += ls.getChangedPaths().size();
            }
        } catch (SVNException e) {
            e.printStackTrace();
        }
        return sum;
    }


    /**
     * 获取:1:今天 2:近一周 3:近一个月的数据
     * @return
     */
    public Map<String,Object> commitCount(){
        LocalDate localDate = new DateTime().toLocalDate();
        LocalDate localDateSeven = new DateTime().minusDays(SvnTimeConstants.seven).toLocalDate();
        LocalDate localDateThirty = new DateTime().minusDays(SvnTimeConstants.Thirty).toLocalDate();
        int today = countSum(localDate.toDate());
        int sevenToday = countSum(localDateSeven.toDate());
        int thirtyToday = countSum(localDateThirty.toDate());
        Map<String,Object> map = Maps.newHashMap();
        map.put("today",today);
        map.put("sevenToday",sevenToday);
        map.put("thirtyToday",thirtyToday);
        return map;
    }

    public Map<String,Object> dmCount(){
        Map<String,Object> map = Maps.newHashMap();
        //日期改成时间排列
        LocalDate now = new DateTime().toLocalDate();
        LocalDate one = new DateTime().minusDays(SvnTimeConstants.one).toLocalDate();
        LocalDate two = new DateTime().minusDays(SvnTimeConstants.two).toLocalDate();
        LocalDate three = new DateTime().minusDays(SvnTimeConstants.three).toLocalDate();
        LocalDate four = new DateTime().minusDays(SvnTimeConstants.four).toLocalDate();
        LocalDate five = new DateTime().minusDays(SvnTimeConstants.five).toLocalDate();
        LocalDate six = new DateTime().minusDays(SvnTimeConstants.six).toLocalDate();
        LocalDate seven = new DateTime().minusDays(SvnTimeConstants.seven).toLocalDate();

        int now_count = dmCountSum(now.toDate());
        int one_count = dmCountSum(one.toDate())-now_count;
        int two_count = dmCountSum(two.toDate())-one_count;
        int three_count = dmCountSum(three.toDate())-two_count;
        int four_count = dmCountSum(four.toDate())-three_count;
        int five_count = dmCountSum(five.toDate())-four_count;
        int six_count = dmCountSum(six.toDate())-five_count;
        int seven_count = dmCountSum(seven.toDate())-six_count;

        map.put("now",now_count);
        map.put("one",one_count);
        map.put("two",two_count);
        map.put("three",three_count);
        map.put("four",four_count);
        map.put("five",five_count);
        map.put("six",six_count);
        map.put("seven",seven_count);
        return map;
    }
}
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐