1. /**
    * Created by wu-yj on 2016/5/6.
    */
  2.  
  3. import java.sql.{Connection, DriverManager, PreparedStatement}
  4.  
  5. import org.apache.spark.{SparkConf, SparkContext}
    import java.sql.{Connection, DriverManager}
  6.  
  7. import org.apache.spark.{SparkConf, SparkContext}
    import org.apache.spark.sql.hive.HiveContext
  8.  
  9. import java.util.Date
    import java.text.SimpleDateFormat
  10.  
  11. class zhengxin_dis{
  12.  
  13. }
  14.  
  15. object zhengxin_dis {
    def main(args: Array[String]) {
    //链接Mysql
    val driver = "com.mysql.jdbc.Driver"
    val url = "jdbc:mysql://10.1.2.190:8066/mq_sale_disc"
    val username = "kr.user"
    val password = "user@85263382"
    var connectionMqcrm: Connection = null
    Class.forName(driver)
    connectionMqcrm = DriverManager.getConnection(url, username, password)
    val statement = connectionMqcrm.createStatement()
  16.  
  17. //链接Hive
    val sparkconf = new SparkConf().setMaster("spark://10.1.2.70:7077").setAppName("local")
    val sc = new SparkContext(sparkconf)
    val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc)
  18.  
  19. //定义城市级别
    val oneline: List[String] = List("北京", "上海 ", "广州 ", "深圳 ")
    val twoline: List[String] = List("杭州", "宁波 ", "西安 ", "温州 ", "佛山 ", "东莞 ", "成都 ", "武汉 ", "哈尔滨 ", "青岛 ", "大连 ", "厦门 ",
    "沈阳 ", "长春 ", "长沙 ", "福州 ", "郑州 ", "石家庄 ", "苏州 ", "南京 ", "济南 ", "重庆 ", "无锡 ",
    "烟台 ", "太原 ", "合肥 ", "南昌 ", "南宁 ", "昆明 ", "淄博 ", "唐山 ")
    val threeline: List[String] = List("绍兴", "台州 ", "嘉兴 ", "榆林 ", "义乌 ", "金华 ", "中山 ", "惠州 ", "茂名 ", "江门 ", "湛江 ", "宝鸡 ", "珠海 ")
    val fourline: List[String] = List("咸阳", "肇庆 ", "汕头 ", "揭阳 ", "延安 ", "渭南 ", "清远 ", "衢州 ", "韶关 ", "丽水 ", "阳江 ")
  20.  
  21. val rdd1 = sqlContext.sql("use moreqinrdb")
    val namelist = sqlContext.sql("select company_name from company_business_info")
    val namelistt=namelist.take(5)
    //计算征信得分过程
    for (coname <- namelistt) {
    //法定代表人
    var score = 0
    val sqllegal = sqlContext.sql("select legal_representative from company_business_info where company_name = \'" + coname + "\'")
    if (sqllegal.count() > 0) {
    val legal = sqllegal.take(1)(0).toString().replace("[", "").replace("]", "")
    if (legal != "" && (legal != "null" || legal != "None"))
    score += 100
    else
    score += 90
    } else
    score += 90
    //公司类型
    val sqlcompanytype = sqlContext.sql("select company_type from company_business_info where company_name = \'" + coname + "\'")
    if (sqlcompanytype.count() > 0) {
    val companytype = sqlcompanytype.take(1)(0).toString().replace("[", "").replace("]", "")
    if (companytype.contains("无限责任"))
    score += 100
    else if (companytype.contains("有限股份") || companytype.contains("无限股份") || companytype.contains("股份两合"))
    score += 90
    else if (companytype.contains("两合公司"))
    score += 80
    else if (companytype.contains("股份有限"))
    score += 60
    else if (companytype.contains("个体"))
    score += 20
    else if (companytype.contains("有限责任"))
    score += 40
    else
    score += 0
    } else
    score += 0
    //经营状态
    val sqlmanagementform = sqlContext.sql("select operation_status from company_business_info where company_name = \'" + coname + "\'")
    sqlmanagementform.show()
    if (sqlmanagementform.count() > 0) {
    val managementform = sqlmanagementform.take(1)(0).toString().replace("[", "").replace("]", "")
    if (managementform == "开业")
    score += 80
    else if (managementform == "存续")
    score += 100
    else if (managementform == "迁出")
    score += 50
    else if (managementform == "吊销")
    score += 0
    else if (managementform == "迁入" || managementform == "待迁入")
    score += 60
    else if (managementform == "歇业")
    score += 30
    else
    score += 0
    } else
    score += 0
    //成立时间
    val sqlfoundtime = sqlContext.sql("select build_date from company_business_info where company_name = \'" + coname + "\'")
    if (sqlfoundtime.count() > 0) {
    val foundtime = sqlfoundtime.take(1)(0).toString().replace("[", "").replace("]", "")
    if (foundtime.length > 1 && foundtime != "null" && foundtime != "None" && foundtime != "") {
    if (foundtime != "None" || foundtime != "null" || foundtime != "") {
    val time = System.currentTimeMillis()
    var dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
    var now: Date = new Date(time)
    val currentTime = dateFormat.format(now)
    val daydiff = dateFormat.parse(currentTime).getTime - dateFormat.parse(foundtime).getTime
    val dayinter = daydiff / (1000 * 3600 * 24)
    var timeyear = dayinter / 365
    if (timeyear > 30)
    score += 100
    if (timeyear >= 10 && timeyear <= 30)
    score += 90
    if (timeyear >= 5 && timeyear < 10)
    score += 80
    if (timeyear >= 3 && timeyear < 5)
    score += 60
    if (timeyear > 1 && timeyear < 3)
    score += 30
    if (timeyear < 1 && timeyear >= 0)
    score += 0
    } else
    score += 0
    } else
    score += 0
    } else
    score += 0
    //注册资本
    val sqlcapital = sqlContext.sql("select registered_capital from company_business_info where company_name = \'" + coname + "\'")
    if (sqlcapital.count() > 0) {
    val capital = sqlcapital.take(1)(0).toString().replace("[", "").replace("]", "")
    if (capital.length > 0) {
    if (capital.contains("人民币")) {
    val zibencl = capital.subSequence(0, capital.indexOf("万"))
    if (zibencl.toString().contains(",")) {
    val ziben = zibencl.toString().replace(",", "").toInt
    if (ziben >= 10000)
    score += 100
    else if (ziben >= 5000 && ziben < 10000)
    score += 90
    else if (ziben >= 3000 && ziben < 5000)
    score += 80
    else if (ziben >= 1000 && ziben < 3000)
    score += 70
    else if (ziben >= 500 && ziben < 1000)
    score += 50
    else if (ziben >= 100 && ziben < 500)
    score += 30
    else if (ziben < 100)
    score += 0
    } else {
    val ziben = zibencl.toString().toFloat
    if (ziben >= 500 && ziben < 1000)
    score += 50
    else if (ziben >= 100 && ziben < 500)
    score += 30
    else if (ziben < 100)
    score += 0
    }
    } else if (capital.contains("美元")) {
    val zibencl = capital.subSequence(0, capital.indexOf("万"))
    if (zibencl.toString().contains(",")) {
    val ziben = zibencl.toString().toFloat * 6.8
    if (ziben >= 10000)
    score += 100
    else if (ziben >= 5000 && ziben < 10000)
    score += 90
    else if (ziben >= 3000 && ziben < 5000)
    score += 80
    else if (ziben >= 1000 && ziben < 3000)
    score += 70
    else if (ziben >= 500 && ziben < 1000)
    score += 50
    else if (ziben >= 100 && ziben < 500)
    score += 30
    else if (ziben < 100)
    score += 0
    } else {
    val ziben = zibencl.toString().toFloat * 6.8
    if (ziben >= 5000 && ziben < 10000)
    score += 90
    else if (ziben >= 3000 && ziben < 5000)
    score += 80
    else if (ziben >= 1000 && ziben < 3000)
    score += 70
    else if (ziben >= 500 && ziben < 1000)
    score += 50
    else if (ziben >= 100 && ziben < 500)
    score += 30
    else if (ziben < 100)
    score += 0
    }
    } else {
    score += 0
    }
    } else {
    score += 0
    }
    } else
    score += 0
    //登记机关
    val sqlregister = sqlContext.sql("select registration_authority from company_business_info where company_name = \'" + coname + "\'")
    if (sqlregister.count() > 0) {
    val register = sqlregister.take(1)(0).toString().replace("[", "").replace("]", "")
    if (register.length > 1) {
    if (register.contains("县"))
    score += 20
    else if (register.contains("市") == true && register.contains("区") == true && register.contains("省") == true) {
    val subS = register.subSequence(register.indexOf("省") + 1, register.indexOf("市") + 1)
    if (oneline.contains(subS))
    score += 100
    else if (twoline.contains(subS))
    score += 80
    else if (threeline.contains(subS))
    score += 60
    else if (fourline.contains(subS))
    score += 40
    else if (oneline.contains(subS) == false && twoline.contains(subS) == false && threeline.contains(subS) == false && fourline.contains(subS) == false)
    score += 20
    } else if (register.contains("市") == true && register.contains("省") == true && register.contains("区") == false) {
    val subS = register.subSequence(register.indexOf("省") + 1, register.indexOf("市") + 1)
    if (oneline.contains(subS))
    score += 100
    else if (twoline.contains(subS))
    score += 80
    else if (threeline.contains(subS))
    score += 60
    else if (fourline.contains(subS))
    score += 40
    else if (oneline.contains(subS) == false && twoline.contains(subS) == false && threeline.contains(subS) == false && fourline.contains(subS) == false)
    score += 20
    } else if (register.contains("市") == true && register.contains("区") == true && register.contains("省") == false) {
    val subS = register.subSequence(0, register.indexOf("市") + 1)
    if (oneline.contains(subS))
    score += 100
    else if (twoline.contains(subS))
    score += 80
    else if (threeline.contains(subS))
    score += 60
    else if (fourline.contains(subS))
    score += 40
    else if (oneline.contains(subS) == false && twoline.contains(subS) == false && threeline.contains(subS) == false && fourline.contains(subS) == false)
    score += 20
    } else if (register.contains("市") == true && register.contains("区") == false && register.contains("省") == false) {
    val subS = register.subSequence(0, register.indexOf("市") + 1)
    if (oneline.contains(subS))
    score += 100
    else if (twoline.contains(subS))
    score += 80
    else if (threeline.contains(subS))
    score += 60
    else if (fourline.contains(subS))
    score += 40
    else if (oneline.contains(subS) == false && twoline.contains(subS) == false && threeline.contains(subS) == false && fourline.contains(subS) == false)
    score += 20
    } else if (register.contains("市") == false && register.contains("区") == true && register.contains("省") == false) {
    score == 20
    } else
    score += 0
    } else
    score += 0
    } else
    score += 0
    //股东信息
    val sqlshareholder = sqlContext.sql("select stock_holder_type from stock_holder_info where company_name = \'" + coname + "\'")
    if (sqlshareholder.count() > 0) {
    val shareholder = sqlshareholder.take(1)(0).toString().replace("[", "").replace("]", "")
    if (shareholder.contains("法人"))
    score += 100
    else if (shareholder.contains("自然人"))
    score += 50
    else
    score += 0
    } else
    score += 0
    //主要人员
    val sqlkeymember = sqlContext.sql("select manager_occupation from managers_info where company_name = \'" + coname + "\'")
    if (sqlkeymember.count() > 0) {
    val keymember = sqlkeymember.take(1)(0).toString().replace("[", "").replace("]", "")
    if (keymember.contains("监事"))
    score += 100
    else
    score += 50
    } else
    score += 0
    //法院判决
    val sqlcourtdecision = sqlContext.sql("select judge_role from judicial_decision where company_name = \'" + coname + "\'")
    if (sqlcourtdecision.count() > 0) {
    val courtdecision = sqlcourtdecision.take(1)(0).toString().replace("[", "").replace("]", "")
    var countdc = 0
    if (courtdecision.contains("被告")) {
    countdc += 1
    }
    score -= countdc * 10
    } else
    score += 0
    //被执行人信息
    val sqlexecuteinfo = sqlContext.sql("select filing_time from judicial_decision_execution where company_name =\'" + coname + "\'")
    if (sqlexecuteinfo.count() > 0) {
    val executeinfo = sqlexecuteinfo.take(1)(0).toString().replace("[", "").replace("]", "")
    val countexin = executeinfo.length
    var num = 0
    for (re <- executeinfo) {
    if (re.toString() == "" || re.toString() == "None")
    num += 1
    }
    score -= (countexin - num) * 10
    } else
    score += 0
    //失信人信息
    val sqllosefaith = sqlContext.sql("select *from dishonest_info where company_name =\'" + coname + "\'")
    if (sqllosefaith.count() > 0) {
    val losefaith = sqllosefaith.take(1)(0).toString().replace("[", "").replace("]", "")
    val countlose = losefaith.length
    if (countlose > 0)
    score += -100
    else
    score += 0
    } else
    score += 0
    //经营异常
    val sqlrununusual = sqlContext.sql("select inclusion_date from company_exception_info where company_name =\'" + coname + "\'")
    if (sqlrununusual.count() > 0) {
    val rununusual = sqlrununusual.take(1)(0).toString().replace("[", "").replace("]", "")
    val countrun = rununusual.length
    score += -10 * countrun
    } else
    score += 0
    //对外投资
    val sqlinvestment = sqlContext.sql("select investment_company_name from investment_company_info where parent_company_name =\'" + coname + "\'")
    if (sqlinvestment.count() > 0) {
    val investment = sqlinvestment.take(1)(0).toString().replace("[", "").replace("]", "")
    val countment = investment.length
    score += 5 * countment
    } else
    score += 0
    //企业基本年报
    val sqlreport = sqlContext.sql("select *from company_basic_info where company_name =\'" + coname + "\'")
    if (sqlreport.count() > 0) {
    val report = sqlreport.take(1)(0).toString().replace("[", "").replace("]", "")
    val countreport = report.length
    if (countreport > 0)
    score += 50
    else
    score += 0
    } else
    score += 0
    if (score < 0)
    score = 0
    else {
    score = score
    }
    //生成ID
    var count = 0
    val sqlname = "insert into tmp_enterprise( ENTERPRISE_NAME ) values (\'" + coname + "\') "
    val sqlcount = "select count(*) from tmp_enterprise where ENTERPRISE_NAME =\'" + coname + "\' "
    var ecusqlcount = statement.executeQuery(sqlcount)
    while (ecusqlcount.next()){
    count = ecusqlcount.getInt(1)
    }
    if (count >0) {
    val ecusqlname = statement.executeUpdate(sqlname)
    }
    //插入征信分数
    var countnum =0
    var companyID = 0
    val sqlID = "select ENTERPRISE_ID from tmp_enterprise where ENTERPRISE_NAME= \'" + coname +"\' "
    val ecusqlID = statement.executeQuery(sqlID)
    while (ecusqlID.next()){
    companyID = ecusqlID.getInt("ENTERPRISE_ID")
    }
    val timenew = System.currentTimeMillis()
    var dateFormat: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
    var nowtime: Date = new Date(timenew)
    val currentTimenew = dateFormat.format(nowtime)
    val sqlscore = "insert into tm_enterprise_credit(CREATE_TIME ,UPDATE_TIME , ENTERPRISE_ID, CREDIT_SCORE ) values( \'" + currentTimenew + "\' , \'" + currentTimenew + "\',\'" + companyID + "\',\'" + score + "\')"
    val sqlcountN = "select count(*) from tm_enterprise_credit where ENTERPRISE_ID = \'" + companyID + "\'"
    val ecusqlcountN = statement.executeQuery(sqlcountN)
    while (ecusqlcountN.next()){
    countnum = ecusqlcountN.getInt(1)
    }
    if (countnum > 0 ) {
    val sqlnew = "update tm_enterprise_credit set CREDIT_SCORE= \'" + score + " \' , UPDATE_TIME= \'" + currentTimenew + "\'" + "where ENTERPRISE_ID= \'" + companyID + "\'"
    val ecusqlnew = statement.executeUpdate(sqlnew)
    } else {
    val ecusqlscore = statement.executeUpdate(sqlscore)
    }
    }
    }
    }

company_credit的更多相关文章

随机推荐

  1. Java集合List、Set、Map

    集合是 java 基础中非常重要的一部分,同样也是 Java 面试中很重要的一个知识点.所以,给王小整理了这篇关于集合的文章. 1.接口继承关系以及实现 集合类存放于 Java.util 包中,主要有 ...

  2. turtlebot3 ubuntu mate 实现vnc连接

    tuutlebot3 ubuntu mate 实现vnc连接 摘要: 在turtlebot3 安装的nbuntu mate系统实验过. 实现内容 x11vnc 安装 x11vnc自动启动 vnc分辩率 ...

  3. 搭建MHA测试

    搭建MHA:  手工切换:  masterha_master_switch --conf=/etc/masterha/app1.cnf --master_state=alive --new_maste ...

  4. 【Idea】-NO.162.Idea.1 -【Idea Unable to import maven project: See logs for details】

    Style:Mac Series:Java Since:2018-09-10 End:2018-09-10 Total Hours:1 Degree Of Diffculty:5 Degree Of ...

  5. 输入参数的默认值设定${3:-var_d}

    今天看到一个不一样的写法: if [ $# != 2 ] && [ $# != 3 ] ; then #判断参数个数    echo "Invalid Args"  ...

  6. Oracle 11g R2 Backup Data Pump(数据泵)之expdp/impdp工具

    Oracle Data Pump(以下简称数据泵)是Oracle 10g开始提供的一种数据迁移工具,同时也被广大DBA用来作为数据库的逻辑备份工具和体量较小的数据迁移工具.与传统的数据导出/导入工具, ...

  7. Mac截图操作,自定义快捷键

    选择system preferences 下面能看到系统定义的快捷键,可以自己修改

  8. Cocos Creator 按钮音效封装重写

    cc.Button.prototype._onTouchEnded = function (t) { cc.hb.audioMgr.playMusic("click", false ...

  9. 算法题:int 数组中 只有一个是id 只出现一次 其他都出现2次 怎么找出只出现一次的id

    首先讲一个最笨的算法:时间复杂度为N  空间复杂度为N 代码如下:输出结果id=3完全正确: int[] a = new int[] { 1, 1, 2, 2, 3, 4, 4 }; Dictiona ...

  10. 关于SimpleDateFormat安全的时间格式化线程安全问题

    想必大家对SimpleDateFormat并不陌生.SimpleDateFormat 是 Java 中一个非常常用的类,该类用来对日期字符串进行解析和格式化输出,但如果使用不小心会导致非常微妙和难以调 ...