Commit 213544c6 by 朱继来

拉取风控公司信息

parent 17895640
......@@ -9,7 +9,11 @@ tuangou_webhook="https://oapi.dingtalk.com/robot/send?access_token=a13d6128de5f9
erpLabel_webhook="https://oapi.dingtalk.com/robot/send?access_token=3966b80b7e56e8ffdff5ed2aefa1ea465c0f944a0db6ec5519eeef8721d1eb43"
yaoHaoYou_hook="https://oapi.dingtalk.com/robot/send?access_token=087c11504fb541d004507f06285da88c2501fc1a4ecacd0216b9da964aa65518"
bomCreateBom="https://oapi.dingtalk.com/robot/send?access_token=0fc661fcbb51d312780c0245986363a38c788c50c2e652e7f250df4f393ae938"
fk_company="https://oapi.dingtalk.com/robot/send?access_token=231bee055924688720f72a0f6e413439d273d8613590cb3a5f174c3867722958"
[Api_domain]
api_url="http://api.liexin.com/"
[Fengkong_domain]
go_url="http://192.168.2.179:8000"
\ No newline at end of file
......@@ -9,6 +9,10 @@ tuangou_webhook="https://oapi.dingtalk.com/robot/send?access_token=a13d6128de5f9
erpLabel_webhook="https://oapi.dingtalk.com/robot/send?access_token=ba4ed87924ee03b37d2b96ba0f0cb1a28d476bda3af6b2e75a2458b08b5ae39c"
yaoHaoYou_hook="https://oapi.dingtalk.com/robot/send?access_token=09333ef25d736b34268fff237d58a4f27c7d33b01be37aa5c0c30acf5a7356e4"
bomCreateBom="https://oapi.dingtalk.com/robot/send?access_token=64d1d9d89d51aa66fe5cbbfe5cbdd7595202d43e255fab28adcbe60a9bd5f11d"
fk_company="https://oapi.dingtalk.com/robot/send?access_token=231bee055924688720f72a0f6e413439d273d8613590cb3a5f174c3867722958"
[Api_domain]
api_url="http://api.ichunt.com/"
[Fengkong_domain]
go_url="http://192.168.2.179:8000"
\ No newline at end of file
package InvoiceCompany
import (
_ "encoding/json"
_ "github.com/ichunt2019/logger"
)
type Company struct {
Id int `db:"id"`
ComSn string `db:"com_sn"`
ErpComSn string `db:"erp_com_sn"`
ComName string `db:"com_name"`
ComAddr string `db:"com_addr"`
EstablishmentTime int `db:"establishment_time"`
RegisteredCapital float64 `db:"registered_capital"`
ComOrganization string `db:"com_organization"`
LegalRepresentative string `db:"legal_representative"`
FiveLegalChange int `db:"five_legal_change"`
TwoYearsNoLawsuit string `db:"two_years_no_lawsuit"`
TotalCreditScore float64 `db:"total_credit_score"`
IchuntHuntingCore int `db:"ichunt_hunting_core"`
BlacklistHit string `db:"blacklist_hit"`
RiskType string `db:"risk_type"`
IsKefuCertified string `db:"is_kefu_certified"`
CreateTime int `db:"create_time"`
UpdateTime int `db:"update_time"`
}
package main
import (
"flag"
"fmt"
"github.com/ichunt2019/logger"
"go-queue-server/dal/db"
"go-queue-server/util"
"go-queue-server/util/ding"
"io/ioutil"
"net/http"
"time"
"go-queue-server/dal/user/InvoiceCompany"
"github.com/tidwall/gjson"
)
func initDb(dns string) (err error) {
err = db.Init(dns)
if err != nil {
return
}
return
}
var ConfigDir string
var LogDir string
// 解析命令行参数
func initArgs() {
// worker -config ./worker.json
// worker -h
flag.StringVar(&ConfigDir, "configDir", "", "配置文件")
flag.StringVar(&LogDir, "logDir", "", "日志目录")
flag.Parse()
}
// 从风控系统拉取公司信息
func main() {
initArgs()
//初始化配置文件
util.Init(ConfigDir)
logConfig := make(map[string]string)
logConfig["log_path"] = LogDir+"user/company"
logConfig["log_chan_size"] = "1000"
logger.InitLogger("file",logConfig)
logger.Init()
//初始化db
initDb(util.Configs.Liexin_databases.Dns)
//t1 := time.NewTimer(time.Second * 3)
t1 := time.NewTimer(time.Hour * 12) // 定时12小时
for {
select {
case <-t1.C:
fmt.Println("ticker...")
updateData()
//t1.Reset(time.Second * 3)
t1.Reset(time.Hour * 12)
}
}
}
// 修改DB
func updateData() (err error) {
// 获取未评分的公司
row, err := db.DB.Queryx("select * from lie_invoice_company where total_credit_score = 0")
if err != nil {
logger.Info("获取未评分公司失败,DB错误原因: ", err.Error())
return
}
for row.Next() {
var company InvoiceCompany.Company
row.StructScan(&company)
// 拉取风控公司信息
url := util.Configs.Fengkong_domain.GoUrl + "/kaopu-server/http/member/company_info/" + company.ComName
resp, err := http.Get(url)
if err != nil {
logger.Info("请求风控接口失败,错误原因: ", err.Error())
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
erp_com_sn := gjson.Get(string(body), "com_credit.erp_company_code").String() // ERP编码
com_addr := gjson.Get(string(body), "com_basic_info.com_address").String() // 公司地址
establishment_time := gjson.Get(string(body), "com_basic_info.establishment_time").Int() // 成立时间
registered_capital := gjson.Get(string(body), "com_basic_info.registered_capital").Float() // 注册资本
com_organization := gjson.Get(string(body), "com_basic_info.com_organization").String() // 组织结构代码
legal_representative := gjson.Get(string(body), "com_basic_info.legal_representative").Float() // 法定代表人
five_legal_change := gjson.Get(string(body), "com_basic_info.five_legal_change").Int() // 5年内法人变更次数
two_years_no_lawsuit := gjson.Get(string(body), "com_basic_info.two_years_no_lawsuit").String() // 近两年内有无诉讼
total_credit_score := gjson.Get(string(body), "com_credit.total_credit_score").Float() // 信用评分
ichunt_hunting_core := gjson.Get(string(body), "com_credit.ichunt_hunting_core").Int() // 评分分级
blacklist_hit := gjson.Get(string(body), "com_credit.blacklist_hit").String() // 黑名单命中
risk_type := gjson.Get(string(body), "com_credit.risk_type").String() // 风险分类
curr_time := time.Now().Unix()
// 更新发票公司表
_, err = db.DB.Exec("update lie_invoice_company set erp_com_sn = ?, com_addr = ?, establishment_time = ?, registered_capital = ?, com_organization = ?," +
"legal_representative = ?, five_legal_change = ?, two_years_no_lawsuit = ?, total_credit_score = ?, ichunt_hunting_core = ?, blacklist_hit = ?, " +
"risk_type = ?, update_time = ? where com_name = ?", erp_com_sn, com_addr, establishment_time, registered_capital, com_organization, legal_representative,
five_legal_change, two_years_no_lawsuit, total_credit_score, ichunt_hunting_core, blacklist_hit, risk_type, curr_time, company.ComName)
var mobile []string = make([]string, 0)
var isAtAll bool = false
if err != nil {
ding.Send(util.Configs.Ding_msg.FkCompany, "任务告警", "更新发票公司失败,错误原因: "+err.Error()+",公司名称:"+company.ComName, mobile, isAtAll)
logger.Info("更新发票公司失败,错误原因: "+err.Error()+",公司名称:"+company.ComName)
return err
}
ding.Send(util.Configs.Ding_msg.FkCompany, "任务告警", "获取风控公司信息成功,公司名称:"+company.ComName, mobile, isAtAll)
}
return
}
......@@ -19,6 +19,7 @@ type Config struct{
Ding_msg *Ding
Api_domain *ApiDomain
Redis_config *RedisConn
Fengkong_domain *FengkongDomain
}
......@@ -81,6 +82,7 @@ type Ding struct {
ErpLabelWebhook string `toml:"erpLabel_webhook"`
YaoHaoYouWebhook string `toml:"yaoHaoYou_hook"`
BomCreateOrderhook string `toml:"bomCreateBom_hook"`
FkCompany string `toml:"fk_company"`
}
type ApiDomain struct {
......@@ -93,6 +95,10 @@ type RedisConn struct {
Port string `toml:"port"`
}
type FengkongDomain struct {
GoUrl string `toml:"go_url"`
}
var Configs *Config =new (Config)
func Init(ConfigDir string){
......
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 sign in to comment