|
@@ -0,0 +1,213 @@
|
|
|
+package com.winhc.bigdata.spark.jobs
|
|
|
+
|
|
|
+import java.util.Date
|
|
|
+import com.winhc.bigdata.calc.DimScoreV2
|
|
|
+import com.winhc.bigdata.spark.utils.{BaseUtil, LoggingUtils, SparkUtils}
|
|
|
+import org.apache.spark.sql.{Row, SparkSession}
|
|
|
+import scala.annotation.meta.getter
|
|
|
+import scala.collection.mutable
|
|
|
+
|
|
|
+/**
|
|
|
+ * 软件著作权 | 作品著作权 | 专利
|
|
|
+ * π
|
|
|
+ */
|
|
|
+
|
|
|
+object CompanyIntellectualsScore {
|
|
|
+
|
|
|
+ val tabMapping: Map[String, (String, String, String, String)] =
|
|
|
+ Map("ads_company_copyright_reg_list" -> ("1", "publish_time", "资产权益", "软著作权"), //软件著作权
|
|
|
+ "ads_company_copyright_works_list" -> ("2", "finish_time", "资产权益", "著作权"), //作品著作权
|
|
|
+ "ads_company_patent_list" -> ("3;4", "pub_date", "资产权益", "实用新型、外观设计专利;发明专利") //专利
|
|
|
+ )
|
|
|
+
|
|
|
+ def main(args: Array[String]): Unit = {
|
|
|
+
|
|
|
+ val (sourceTable, flag, time, kind, project) = valid(args)
|
|
|
+
|
|
|
+ var config = mutable.Map.empty[String, String]
|
|
|
+
|
|
|
+ val spark: SparkSession = SparkUtils.InitEnv(this.getClass.getSimpleName, config)
|
|
|
+
|
|
|
+ println(s"company ${this.getClass.getSimpleName} calc start! " + new Date().toString)
|
|
|
+
|
|
|
+ //专利分成两部分
|
|
|
+ if (flag.contains(";")) {
|
|
|
+ flag.split(";").foreach(f => {
|
|
|
+ new CompanyIntellectualsScore(spark, sourceTable, f, time, kind, project).calc()
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ new CompanyIntellectualsScore(spark, sourceTable, flag, time, kind, project).calc()
|
|
|
+ }
|
|
|
+
|
|
|
+ println(s"company ${this.getClass.getSimpleName} calc end! " + new Date().toString)
|
|
|
+ spark.stop()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ def valid(args: Array[String]) = {
|
|
|
+ if (args.length != 1) {
|
|
|
+ println("请输入要计算的table!!!! ")
|
|
|
+ sys.exit(-1)
|
|
|
+ }
|
|
|
+ val Array(sourceTable) = args
|
|
|
+
|
|
|
+ val (flag, time, kind, project) = tabMapping.getOrElse(sourceTable, ("", "", "", ""))
|
|
|
+ if (flag.isEmpty || time.isEmpty || kind.isEmpty || project.isEmpty) {
|
|
|
+ println("输入表不存在!!! ")
|
|
|
+ sys.exit(-1)
|
|
|
+ }
|
|
|
+ (sourceTable, flag, time, kind, project)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+case class CompanyIntellectualsScore(s: SparkSession, sourceTable: String,
|
|
|
+ flag: String, time: String, kind: String, project: String
|
|
|
+ ) extends LoggingUtils {
|
|
|
+
|
|
|
+ @(transient@getter) val spark: SparkSession = s
|
|
|
+
|
|
|
+ import spark.implicits._
|
|
|
+
|
|
|
+ def calc(): Unit = {
|
|
|
+ var appsql = ""
|
|
|
+ var apptab = ""
|
|
|
+ if ("3".equals(flag)) { //实用新型、外观设计专利
|
|
|
+ appsql = "AND substring(pub_number, 7,1) in ('2','3')"
|
|
|
+ apptab = "_s"
|
|
|
+ } else if ("4".equals(flag)) { //发明专利
|
|
|
+ appsql = "AND substring(pub_number, 7,1) not in ('2','3')"
|
|
|
+ apptab = "_f"
|
|
|
+ }
|
|
|
+
|
|
|
+ val df = sql(
|
|
|
+ s"""
|
|
|
+ |SELECT *
|
|
|
+ |FROM (
|
|
|
+ | SELECT
|
|
|
+ | *
|
|
|
+ | ,COUNT(new_cid) OVER(PARTITION BY new_cid ) AS cnt1
|
|
|
+ | ,row_number() OVER(PARTITION BY new_cid ORDER BY $time DESC ) AS num
|
|
|
+ | FROM $sourceTable
|
|
|
+ | WHERE ds = '${BaseUtil.getPartion(sourceTable, spark)}'
|
|
|
+ | AND new_cid IS NOT NULL ${appsql}
|
|
|
+ | ) a
|
|
|
+ |WHERE num =1
|
|
|
+ |""".stripMargin)
|
|
|
+
|
|
|
+ df.map(r => {
|
|
|
+ trans(r, flag, kind, project)
|
|
|
+ }).toDF("id", "cid", "kind", "kind_code", "project", "project_code", "type",
|
|
|
+ "score", "total", "extraScore")
|
|
|
+ .createOrReplaceTempView(s"${sourceTable}_tmp_view")
|
|
|
+
|
|
|
+ logger.info(
|
|
|
+ s"""
|
|
|
+ |- - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+ |${showString(sql(s"select * from ${sourceTable}_tmp_view"))}
|
|
|
+ |- - - - - - - - - - - - - - - - - - - - - - - - -
|
|
|
+ """.stripMargin)
|
|
|
+
|
|
|
+ sql(s"insert overwrite table ${sourceTable}${apptab}_score select * from ${sourceTable}_tmp_view")
|
|
|
+ }
|
|
|
+
|
|
|
+ def trans(r: Row, flag: String, kind: String, prpject: String) = {
|
|
|
+ val id = r.getAs[Long]("id")
|
|
|
+ val cid = r.getAs[Long]("new_cid").toString
|
|
|
+ val cnt1 = r.getAs[Long]("cnt1")
|
|
|
+ flag match {
|
|
|
+ case "1" => getSoftCopyRightScore(id, cid, cnt1, kind, prpject)
|
|
|
+ case "2" => getCopyRightScore(id, cid, cnt1, kind, prpject)
|
|
|
+ case "3" => ordinaryPatentScore(id, cid, cnt1, kind, prpject)
|
|
|
+ case "4" => inventScore(id, cid, cnt1, kind, prpject)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //软著作权
|
|
|
+ def getSoftCopyRightScore(id: Long, cid: String, cnt1: Long, kind: String, project: String) = {
|
|
|
+ var score = 0f
|
|
|
+ val total = 3f
|
|
|
+ val extraScore = 0f
|
|
|
+ var ty = ""
|
|
|
+ if (cnt1 > 50) {
|
|
|
+ score = 8f
|
|
|
+ ty = "软件著作权数量>50,该项分数上加5分"
|
|
|
+ } else if (cnt1 > 5) {
|
|
|
+ score = 3f
|
|
|
+ ty = "授予数量>5"
|
|
|
+ } else if (cnt1 > 0) {
|
|
|
+ score = 2f
|
|
|
+ ty = "授予数量≤5"
|
|
|
+ } else {
|
|
|
+ score = 1f
|
|
|
+ ty = "无"
|
|
|
+ }
|
|
|
+ (id, cid, kind, DimScoreV2.newsEventMap.get(kind), project, DimScoreV2.newsEventMap.get(project), ty,
|
|
|
+ score, total, extraScore)
|
|
|
+ }
|
|
|
+
|
|
|
+ //著作权
|
|
|
+ def getCopyRightScore(id: Long, cid: String, cnt1: Long, kind: String, project: String) = {
|
|
|
+ var score = 0f
|
|
|
+ val total = 2f
|
|
|
+ val extraScore = 0f
|
|
|
+ var ty = ""
|
|
|
+ if (cnt1 > 3) {
|
|
|
+ score = 2f
|
|
|
+ ty = "授予数量>3"
|
|
|
+ } else if (cnt1 == 0) {
|
|
|
+ score = 0f
|
|
|
+ ty = "无"
|
|
|
+ } else {
|
|
|
+ score = 1f
|
|
|
+ ty = "授予数量≤3"
|
|
|
+ }
|
|
|
+ (id, cid, kind, DimScoreV2.newsEventMap.get(kind), project, DimScoreV2.newsEventMap.get(project), ty,
|
|
|
+ score, total, extraScore)
|
|
|
+ }
|
|
|
+
|
|
|
+ //普通专利
|
|
|
+ def ordinaryPatentScore(id: Long, cid: String, cnt1: Long, kind: String, project: String) = {
|
|
|
+ val project_s = project.split(";")(0)
|
|
|
+ var score = 0f
|
|
|
+ val total = 3f
|
|
|
+ val extraScore = 0f
|
|
|
+ var ty = ""
|
|
|
+ if (cnt1 == 0) {
|
|
|
+ score = 1f
|
|
|
+ ty = "无"
|
|
|
+ } else if (cnt1 <= 5) {
|
|
|
+ score = 2f
|
|
|
+ ty = "授予数量≤5"
|
|
|
+ } else {
|
|
|
+ score = 3f
|
|
|
+ ty = "授予数量>5"
|
|
|
+ }
|
|
|
+ (id, cid, kind, DimScoreV2.newsEventMap.get(kind), project_s, DimScoreV2.newsEventMap.get(project_s), ty,
|
|
|
+ score, total, extraScore)
|
|
|
+ }
|
|
|
+
|
|
|
+ //发明专利
|
|
|
+ def inventScore(id: Long, cid: String, cnt1: Long, kind: String, project: String) = {
|
|
|
+ val project_s = project.split(";")(1)
|
|
|
+ var score = 0f
|
|
|
+ val total = 7f
|
|
|
+ val extraScore = 0f
|
|
|
+ var ty = ""
|
|
|
+ if (cnt1 == 0) {
|
|
|
+ score = 3f
|
|
|
+ ty = "无"
|
|
|
+ } else if (cnt1 <= 3) {
|
|
|
+ score = 5f
|
|
|
+ ty = "授予数量≤3"
|
|
|
+ } else if (cnt1 <= 50) {
|
|
|
+ score = 7f
|
|
|
+ ty = "授予数量>3"
|
|
|
+ } else {
|
|
|
+ score = 12f
|
|
|
+ ty = "发明专利数量>50,该项分数上加5分"
|
|
|
+ }
|
|
|
+ (id, cid, kind, DimScoreV2.newsEventMap.get(kind), project_s, DimScoreV2.newsEventMap.get(project_s), ty,
|
|
|
+ score, total, extraScore)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|