Commit c4e79a47 by 李辅翼

v1

parent 096ce7dd
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -2,20 +2,20 @@
1. com.hikcreate.config<br>
配置文件目录,如:Apollo配置中心,sparkConf配置接口等
2. com.hikcreate.task<br>
业务代码,sparkStreaming处理逻辑
业务代码,sql任务处理逻辑
3. com.hikcreate.model<br>
实体类父目录
4. com.hikcreate.utils<br>
工具类父目录
5. com.hikcreate.launcher<br>
程序入口,通过传入指定参数执行相应的业务
5. lib<br>
6. lib<br>
依赖包,需要上传到hdfs集群上,路径在$SPARK-HOME$/conf/spark-defaults.xml 中指定(spark.yarn.jars)<br>
如: `spark.yarn.jars hdfs://hikbigdata/sparkJar/jars/*.jar`<br>
**注意jar包冲突**<br>
6. script<br>
7. script<br>
服务器脚本,主要作为一个文档管理作用,不作为执行文件,包含spark-submit脚本,hiveSql脚本
7. META-INF/app.properties<br>
8. META-INF/app.properties<br>
Apollo配置中心地址
8. log4j.properties<br>
9. log4j.properties<br>
日志配置文件
app.id=hangzhou-dataprocess
apollo.meta=http://10.197.236.187:7070/
\ No newline at end of file
package com.hikcreate.utils
import java.util.Date
import java.text.SimpleDateFormat
import java.util.{Calendar, Date}
import org.apache.commons.lang3.time.DateFormatUtils
......@@ -9,7 +10,173 @@ object DateUtils {
private val parsePatterns = Array("yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss",
"yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM")
/**
* 得到当前日期字符串 格式(yyyy-MM-dd)
*/
def getDate: String = DateFormatUtils.format(new Date, "yyyy-MM-dd")
/**
* 得到当前日期字符串 格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
*/
def getDate(pattern: String): String = DateFormatUtils.format(new Date, pattern)
/**
* 得到日期字符串 默认格式(yyyy-MM-dd) pattern可以为:"yyyy-MM-dd" "HH:mm:ss" "E"
*/
def formatDate(date: Date, pattern: Any*): String = {
if (date == null) return null
if (pattern != null && pattern.length > 0) DateFormatUtils.format(date, pattern(0).toString)
else DateFormatUtils.format(date, "yyyy-MM-dd")
}
/**
* 得到日期时间字符串,转换格式(yyyy-MM-dd HH:mm:ss)
*/
def formatDateTime(date: Date): String = formatDate(date, "yyyy-MM-dd HH:mm:ss")
/**
* 得到当前时间字符串 格式(HH:mm:ss)
*/
def getTime: String = formatDate(new Date, "HH:mm:ss")
/**
* 得到当前日期和时间字符串 格式(yyyy-MM-dd HH:mm:ss)
*/
def getDateTime: String = formatDate(new Date, "yyyy-MM-dd HH:mm:ss")
/**
* 得到当前年份字符串 格式(yyyy)
*/
def getYear: String = formatDate(new Date, "yyyy")
/**
* 得到当前月份字符串 格式(MM)
*/
def getMonth: String = formatDate(new Date, "MM")
/**
* 得到当天字符串 格式(dd)
*/
def getDay: String = formatDate(new Date, "dd")
/**
* 得到当前星期字符串 格式(E)星期几
*/
def getWeek: String = formatDate(new Date, "E")
/**
* 日期型字符串转化为日期 格式
* { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm",
* "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm",
* "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm" }
*/
def parseDate(str: Any): Date = {
if (str == null) return null
try
parseDate(str.toString, parsePatterns)
catch {
case e: Exception =>
null
}
}
/**
* 获取过去的天数
*
* @param date
* @return
*/
def pastDays(date: Date): Long = {
val t = new Date().getTime - date.getTime
t / (24 * 60 * 60 * 1000)
}
/**
* 获取过去的小时
*
* @param date
* @return
*/
def pastHour(date: Date): Long = {
val t = new Date().getTime - date.getTime
t / (60 * 60 * 1000)
}
/**
* 获取过去的分钟
*
* @param date
* @return
*/
def pastMinutes(date: Date): Long = {
val t = new Date().getTime - date.getTime
t / (60 * 1000)
}
/**
* 转换为时间(天,时:分:秒.毫秒)
*
* @param timeMillis
* @return
*/
def formatDateTime(timeMillis: Long): String = {
val day = timeMillis / (24 * 60 * 60 * 1000)
val hour = timeMillis / (60 * 60 * 1000) - day * 24
val min = (timeMillis / (60 * 1000)) - day * 24 * 60 - hour * 60
val s = timeMillis / 1000 - day * 24 * 60 * 60 - hour * 60 * 60 - min * 60
val sss = timeMillis - day * 24 * 60 * 60 * 1000 - hour * 60 * 60 * 1000 - min * 60 * 1000 - s * 1000
(if (day > 0) day + ","
else "") + hour + ":" + min + ":" + s + "." + sss
}
/**
* 获取两个日期之间的天数
*
* @param before
* @param after
* @return
*/
def getDistanceOfTwoDate(before: Date, after: Date): Double = {
val beforeTime = before.getTime
val afterTime = after.getTime
(afterTime - beforeTime) / (1000 * 60 * 60 * 24)
}
def getFirstDayOfMonth: String = {
val format = new SimpleDateFormat("yyyy-MM-dd")
//获取当前月第一天:
val c = Calendar.getInstance
c.add(Calendar.MONTH, 0)
//设置为1号,当前日期既为本月第一天
c.set(Calendar.DAY_OF_MONTH, 1)
val first = format.format(c.getTime)
first
}
/**
* 将日期加减固定天数
*
* @param date
* @param num
* @return
*/
def getPastDate(date: Date, num: Int): Date = {
val begin = Calendar.getInstance
begin.setTime(date)
begin.add(Calendar.DAY_OF_MONTH, num)
begin.getTime
}
def getDate: String = DateFormatUtils.format(new Date, "yyyy-MM-dd");
}
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