Commit fe80cc12 authored by 史余彬's avatar 史余彬

山东数据推送-静态尾矿库和设备信息结构体,数据库动态切换

parents
Pipeline #134 failed with stages
package common
import "log"
func ErrorPrintln(str string, err error) {
if err != nil{
log.Fatal(str + ":" + err.Error())
}
}
\ No newline at end of file
package common
/*
数据配置信息
*/
type DBConnectInfo struct {
Server string `ini:"db_server"`
Port string `ini:"db_port"`
Username string `ini:"db_username"`
Password string `ini:"db_password"`
DBName string `ini:"db_dbname"`
}
/*
尾矿库基础信息
*/
type TailPondInfor struct {
Tailingno string `xml:"tailingno"`
Tailingname string `xml:"tailingname"`
Unifcreditcode string `xml:"unifcreditcode"`
Address string `xml:"address"`
Unitname string `xml:"unitname"`
Unitaddress string `xml:"unitaddress"`
Industrycharacterno string `xml:"industrycharacterno"`
Unitperson string `xml:"unitperson"`
Unitpersontel string `xml:"unitpersontel"`
Securityofficer string `xml:"securityofficer"`
Securityofficertel string `xml:"securityofficertel"`
Ondutytel string `xml:"ondutytel"`
Longitude float64 `xml:"longitude"`
Latitude float64 `xml:"latitude"`
Useyear float64 `xml:"useyear"`
Operatingstatus string `xml:"operatingstatus"`
Industrytypeno string `xml:"industrytypeno"`
Mineralspecies string `xml:"mineralspecies"`
Top string `xml:"top"`
Onlinemonitoringsys string `xml:"onlinemonitoringsys"`
Geologicalstructure string `xml:"geologicalstructure"`
Topotraphicgradient float64 `xml:"topotraphicgradient"`
Standardizationlevel string `xml:"standardizationlevel"`
Standardforensicsdate string `xml:"standardforensicsdate"`
Safetypermitno string `xml:"safetypermitno"`
Safetypermitdate string `xml:"safetypermitdate"`
Safetypermitunit string `xml:"safetypermitunit"`
Storetypeno string `xml:"storetypeno"`
Designlevel string `xml:"designlevel"`
Grade string `xml:"grade"`
Designheight float64 `xml:"designheight"`
Stackheight float64 `xml:"stackheight"`
Plancapability float64 `xml:"plancapability"`
Nowvolume float64 `xml:"nowvolume"`
Damstocktypeno string `xml:"damstocktypeno"`
Floodequipment string `xml:"floodequipment"`
Floodmethod string `xml:"floodmethod"`
Floodfacilitydischarge string `xml:"floodfacilitydischarge"`
Waterarea float64 `xml:"waterarea"`
Area float64 `xml:"area"`
Floodcontrolstandard float64 `xml:"floodcontrolstandard"`
Damtype string `xml:"damtype"`
Initialdamtype string `xml:"initialdamtype"`
Designinitialdamheight float64 `xml:"designinitialdamheight"`
Currentinitialdamheight float64 `xml:"currentinitialdamheight"`
Initialdamlongness float64 `xml:"initialdamlongness"`
Initialdamsloperatio string `xml:"initialdamsloperatio"`
Accumulationdamratio string `xml:"accumulationdamratio"`
Designsubdamheight float64 `xml:"designsubdamheight"`
Designsubdamtopwidth float64 `xml:"designsubdamtopwidth"`
Accumulateddamsnumber float64 `xml:"accumulateddamsnumber"`
Earthquake float64 `xml:"earthquake"`
Tailingsstoragemethod string `xml:"tailingsstoragemethod"`
Minelaytypeno string `xml:"minelaytypeno"`
Upstreamtailings string `xml:"upstreamtailings"`
Drystorage string `xml:"drystorage"`
Drystoragewaterratio float64 `xml:"drystoragewaterratio"`
Tailingsparticlesize float64 `xml:"tailingsparticlesize"`
Tailingsaveparticlesize float64 `xml:"tailingsaveparticlesize"`
Depositiondrybeachslope float64 `xml:"depositiondrybeachslope"`
Personnum float64 `xml:"personnum"`
Buildingnum float64 `xml:"buildingnum"`
Emergencyplanfiled string `xml:"emergencyplanfiled"`
Primarysafetyunit string `xml:"primarysafetyunit"`
Primarysafetylevel string `xml:"primarysafetylevel"`
Designunit string `xml:"designunit"`
Designunitlevel string `xml:"designunitlevel"`
Constructionunit string `xml:"constructionunit"`
Constructionlevel string `xml:"constructionlevel"`
Supervisoryunit string `xml:"supervisoryunit"`
Supervisorylevel string `xml:"supervisorylevel"`
Safetycheckunit string `xml:"safetycheckunit"`
Safetychecklevel string `xml:"safetychecklevel"`
Safetyacceptancetime string `xml:"safetyacceptancetime"`
Safetyevaluationunit string `xml:"safetyevaluationunit"`
Safetyevaluationlevel string `xml:"safetyevaluationlevel"`
Filingperson string `xml:"filingperson"`
Filingdate string `xml:"filingdate"`
Fillerphone string `xml:"fillerphone"`
Note string `xml:"note"`
InUse string `xml:"in_use"`
IsSync string `xml:"is_sync"`
}
/*
干滩设备信息
*/
type DryBeachEquipInfor struct {
Equipno string `xml:"equipno"`
Equipname string `xml:"equipname"`
Installationdate string `xml:"installationdate"`
Installationlocate string `xml:"installationlocate"`
Manufacture string `xml:"manufacture"`
Longitude float64 `xml:"longitude"`
Latitude float64 `xml:"latitude"`
Altitude float64 `xml:"altitude"`
Onelevelalarm float64 `xml:"onelevelalarm"`
Twolevelalarm float64 `xml:"twolevelalarm"`
Threelevelalarm float64 `xml:"threelevelalarm"`
IsUsed string `xml:"is_used"`
IsSync string `xml:"is_sync"`
}
/*
库水位设备信息
*/
type ReserWaterLevelInfor struct {
Equipno string `xml:"equipno"`
Equipname string `xml:"equipname"`
Installationdate string `xml:"installationdate"`
Installationlocate string `xml:"installationlocate"`
Installlocation float64 `xml:"installlocation"`
Manufacture string `xml:"manufacture"`
Longitude float64 `xml:"longitude"`
Latitude float64 `xml:"latitude"`
Altitude float64 `xml:"altitude"`
Onelevelalarm float64 `xml:"onelevelalarm"`
Twolevelalarm float64 `xml:"twolevelalarm"`
Threelevelalarm float64 `xml:"threelevelalarm"`
IsUsed string `xml:"is_used"`
IsSync string `xml:"is_sync"`
}
/*
表面位移设备信息
*/
type DisplacementInfor struct {
Equipno string `xml:"equipno"`
Equipname string `xml:"equipname"`
Installationdate string `xml:"installationdate"`
Installationlocate string `xml:"installationlocate"`
Manufacture string `xml:"manufacture"`
Longitude float64 `xml:"longitude"`
Latitude float64 `xml:"latitude"`
Altitude float64 `xml:"altitude"`
Onelevelalarm float64 `xml:"onelevelalarm"`
Twolevelalarm float64 `xml:"twolevelalarm"`
Threelevelalarm float64 `xml:"threelevelalarm"`
IsUsed string `xml:"is_used"`
IsSync string `xml:"is_sync"`
}
/*
浸润线设备信息
*/
type SaturationLineInfor struct {
Equipno string `xml:"equipno"`
Equipname string `xml:"equipname"`
Installationdate string `xml:"installationdate"`
Installationlocate string `xml:"installationlocate"`
Manufacture string `xml:"manufacture"`
Holedepth float64 `xml:"holedepth"`
Burialdepth float64 `xml:"burialdepth"`
Longitude float64 `xml:"longitude"`
Latitude float64 `xml:"latitude"`
Altitude float64 `xml:"altitude"`
Onelevelalarm float64 `xml:"onelevelalarm"`
Twolevelalarm float64 `xml:"twolevelalarm"`
Threelevelalarm float64 `xml:"threelevelalarm"`
IsUsed string `xml:"is_used"`
IsSync string `xml:"is_sync"`
}
/*
降雨量设备信息
*/
type RainfallInfor struct {
Equipno string `xml:"equipno"`
Equipname string `xml:"equipname"`
Installationdate string `xml:"installationdate"`
Installationlocate string `xml:"installationlocate"`
Manufacture string `xml:"manufacture"`
Longitude float64 `xml:"longitude"`
Latitude float64 `xml:"latitude"`
Altitude float64 `xml:"altitude"`
Onelevelalarm float64 `xml:"onelevelalarm"`
Twolevelalarm float64 `xml:"twolevelalarm"`
Threelevelalarm float64 `xml:"threelevelalarm"`
IsUsed string `xml:"is_used"`
IsSync string `xml:"is_sync"`
}
/*
内部位移设备信息
*/
type InclinometerInfor struct {
Equipno string `xml:"equipno"`
Equipname string `xml:"equipname"`
Installationdate string `xml:"installationdate"`
Installationlocate string `xml:"installationlocate"`
Manufacture string `xml:"manufacture"`
Longitude float64 `xml:"longitude"`
Latitude float64 `xml:"latitude"`
Altitude float64 `xml:"altitude"`
Onelevelalarm float64 `xml:"onelevelalarm"`
Twolevelalarm float64 `xml:"twolevelalarm"`
Threelevelalarm float64 `xml:"threelevelalarm"`
IsUsed string `xml:"is_used"`
IsSync string `xml:"is_sync"`
}
\ No newline at end of file
[databaseType]
type=sqlserver
[databaseConnection]
db_server=192.168.3.220
db_port=1433
db_username=sa
db_password=1234
db_dbname=mssensors
#基础设备信息
[baiscData]
wkk_no=3706120001
# 01 为干滩;02 为库水位;03 为表面位移;04 为内部位移;05 为浸润线;06 为降雨量
gt_no=370612000101
ksw_no=370612000102
bmwy_no=370612000103
nbwy_no=370612000104
jrx_no=370612000105
jyl_no=370612000106
#尾矿库基础信息
[wkkBasicInfo]
tailingno=3706120001
tailingname=烟台中嘉矿业有限公司尾矿库
unifcreditcode=91370600717854666W
address=烟台市牟平区王格庄镇金城村
unitname=烟台中嘉矿业有限公司
unitaddress=烟台市牟平区王格庄镇前松椒村
industrycharacterno=C5005
unitperson=孔凡忠
unitpersontel=13361311798
securityofficer=周书锋
securityofficertel=18253512978
ondutytel=0535-4755896
longitude=121.408292
latitude=37.097803
usedate=2015-12-15
useyear=32.9
operatingstatus=2
industrytypeno=300000000
mineralspecies=202010000
top=
onlinemonitoringsys=
geologicalstructure=简单
topotraphicgradient=1.5
standardizationlevel=20
standardforensicsdate=2020-04-02
safetypermitno=(鲁)FM安许证字【2017】06-0108
safetypermitdate=2017-12-08-2020-12-07
safetypermitunit=山东省安全生产监督管理局
storetypeno=1
designlevel=3
grade=3
designheight=84.6
stackheight=79.4
plancapability=4222.8
nowvolume=3307
damstocktypeno=1
floodequipment=排水井-排水涵管-隧洞-消力池
floodmethod=
floodfacilitydischarge=12.43
waterarea=1.925
area=1.16
floodcontrolstandard=500
damtype=1
initialdamtype=3
designinitialdamheight=3
currentinitialdamheight=24.6
initialdamlongness=24.6
initialdamsloperatio=1:2.25;1:2.5
accumulationdamratio=1:4
designsubdamheight=3
designsubdamtopwidth=4
accumulateddamsnumber=17
earthquake=7
tailingsstoragemethod=1
minelaytypeno=1
upstreamtailings=1
drystorage=
drystoragewaterratio=
tailingsparticlesize=
tailingsaveparticlesize=
depositiondrybeachslope=
personnum=
buildingnum=
emergencyplanfiled=
primarysafetyunit=
primarysafetylevel=
designunit=
designunitlevel=
constructionunit=
constructionlevel=
supervisoryunit=
supervisorylevel=
safetycheckunit=
safetychecklevel=
safetyacceptancetime=
safetyevaluationunit=
safetyevaluationlevel=
filingperson=
filingdate=
fillerphone=
note=
in_use=
is_sync=
package config
import (
"database/sql"
"fmt"
"gopkg.in/ini.v1"
"log"
"shandong_datapush/common"
_ "github.com/denisenkom/go-mssqldb"
_ "github.com/lib/pq"
)
var (
DBType string
DBConnInfo *common.DBConnectInfo
DB *sql.DB
err error
)
func init() {
file, err := ini.Load("./config/conf.ini")
common.ErrorPrintln("读取配置文件异常", err)
DBType = file.Section("databaseType").Key("type").String()
DBConnInfo = new(common.DBConnectInfo)
err = file.Section("databaseConnection").MapTo(DBConnInfo)
common.ErrorPrintln("数据库连接信息映射异常", err)
}
func DBConnection() {
if DBType == "postgresql" {
log.Println("当前使用pg数据库")
connString := fmt.Sprintf("host=%s port=%s user=%s password=%s dbname=%s sslmode=disable",DBConnInfo.Server, DBConnInfo.Port, DBConnInfo.Username, DBConnInfo.Password, DBConnInfo.DBName)
DB, err = sql.Open("postgres", connString)
err = DB.Ping()
if err != nil {
log.Fatalf("[Error] PG 数据库连接失败: %s", err.Error())
}else {
log.Println("postgres 数据库连接成功!")
}
} else if DBType == "sqlserver" {
log.Println("当前使用SqlServer数据库")
connString := fmt.Sprintf("server=%s;database=%s;user id=%s;password=%s;port=%s;encrypt=disable", DBConnInfo.Server, DBConnInfo.DBName, DBConnInfo.Username, DBConnInfo.Password, DBConnInfo.Port)
DB, err = sql.Open("mssql", connString)
err = DB.Ping()
if err != nil {
log.Fatalf("[Error] sqlserver 数据库连接失败: %s", err.Error())
}else {
log.Println("sqlserver 数据库连接成功!")
}
}
}
\ No newline at end of file
module shandong_datapush
go 1.15
require (
github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204
github.com/lib/pq v1.8.0
gopkg.in/ini.v1 v1.62.0
)
github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204 h1:tI48fqaIkxxYuIylVv1tdDfBp6836GKSfmmzgSyP1CY=
github.com/denisenkom/go-mssqldb v0.0.0-20200910202707-1e08a3fab204/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/lib/pq v1.8.0 h1:9xohqzkUwzR4Ga4ivdTcawVS89YSDVxXMa3xJX3cGzg=
github.com/lib/pq v1.8.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI=
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
package main
import (
"log"
"shandong_datapush/config"
)
func main() {
log.Println("==================数据推送程序启动=================")
config.DBConnection()
}
\ No newline at end of file
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