func main() {
	db, err := sql.Open("mysql", "artogrid:artogrid@tcp(192.168.1.105:3306)/idb_moneymarket?charset=utf8")
	checkErr(err)

	defer db.Close()

	//查询数据
	rows, err := db.Query(`select c.id,c.shortname_cn,c.fullname_cn_front from idb_center.idb_financial_company c where c.status='1' and c.id not in 
       (select company_id from idb_moneymarket.mm_extend_financial_company where broker_company_id='2' and status = '1')`)
	checkErr(err)

	tx, err := db.Begin()
	checkErr(err)

	//插入数据
	insertExtend, err := tx.Prepare(`INSERT mm_extend_financial_company 
SET id=?,company_id=?,level=?,display_name=?,is_fee=?,description=?,is_internal=?,broker_company_id=?,create_time=?,status=?`)
	checkErr(err)

	for rows.Next() {
		var companyId, shortName, fullName []byte
		err = rows.Scan(&companyId, &shortName, &fullName)
		checkErr(err)

		id, err := utils.GenUUID()
		checkErr(err)

		_, err = insertExtend.Exec(id, string(companyId), 0, string(shortName), "2", string(fullName), "2", "2", "2014-01-01 00:00:00", "1")
		checkErr(err)
	}

	tx.Commit()

}
Exemplo n.º 2
0
func WriteLog(w http.ResponseWriter, r *http.Request, log *log.Logger) {
	go func() {
		cookie, _ := r.Cookie("client_uuid")
		if cookie == nil {
			expiration := time.Now()
			expiration = expiration.AddDate(5, 0, 0)
			uuid, _ := utils.GenUUID()
			cookie = &http.Cookie{Name: "client_uuid", Value: uuid, Expires: expiration}
			http.SetCookie(w, cookie)
		}

		path := ""
		clientId := ""
		remoteAddr := ""
		if r != nil {
			if r.URL != nil {
				path = r.URL.Path
			}
			ra := r.RemoteAddr

			remoteAddr = r.Header.Get("X-Forwarded-For")
			if len(remoteAddr) == 0 {
				remoteAddr = strings.Split(ra, ":")[0]
			}
		}

		if cookie != nil {
			clientId = cookie.Value
		}

		_, err := etfWebLogStmt.Exec(path, clientId, remoteAddr, time.Now().Format("2006-01-02 15:04:05"))
		checkErr(err, log)
	}()
}
Exemplo n.º 3
0
func main() {
	brokerCompanyId := "1"

	db, err := sql.Open("mysql", "artogrid:artogrid@tcp(10.10.2.4:3306)/idb_moneymarket?charset=utf8")
	checkErr(err)

	defer db.Close()

	//查询数据
	rows, err := db.Query(fmt.Sprintf(`select company_id,display_name from mm_extend_financial_company c where c.company_id not in (
       select a.company_id from mm_temp_account a,mm_extend_trader t
       where a.id=t.account_id and a.status = '1' and a.broker_company_id='%s'
) and c.company_id not in (
       select a.company_id from idb_center.idb_account a,mm_extend_trader t
       where a.id=t.account_id and a.status = '1'
) and c.status='1' and c.broker_company_id='%s'`, brokerCompanyId, brokerCompanyId))
	checkErr(err)

	tx, err := db.Begin()
	checkErr(err)

	//插入数据
	insertTemp, err := tx.Prepare(`INSERT mm_temp_account
	SET ID=?,COMPANY_ID=?,COMPANY_NAME=?,ACCOUNT_CODE=?,USERNAME=?,PASSWORD=?,DISPLAY_NAME=?,
	ACCOUNT_TYPE=?,IS_FORBIDDEN=?,CREATE_TIME=?,MODIFY_TIME=?,STATUS=?,process_status=?,broker_company_id=?,pinyin_keyword=?`)
	checkErr(err)
	insertExtend, err := tx.Prepare(`INSERT mm_extend_trader
	SET id=?,account_id=?,display_name=?,broker_company_id=?,create_time=?,status=?`)
	checkErr(err)

	i := 500
	for rows.Next() {
		var companyId string
		var companyName string
		err = rows.Scan(&companyId, &companyName)
		checkErr(err)

		id, err := utils.GenUUID()
		checkErr(err)

		name := fmt.Sprintf("trader%v", i)
		ctime := "2014-02-20 11:00:00"

		_, err = insertTemp.Exec(id, companyId, companyName, name, name, "123456", name, "2", "1", ctime, ctime, "1", "2", brokerCompanyId, name)
		checkErr(err)

		_, err = insertExtend.Exec(id, id, name, brokerCompanyId, ctime, "1")
		checkErr(err)

		i++
	}

	tx.Commit()
}
func main() {
	db, err := sql.Open("mysql", "root:root@tcp(localhost:3306)/idb_mm?charset=utf8")
	checkErr(err)

	defer db.Close()

	//插入数据
	insertTemp, err := db.Prepare(`INSERT mm_temp_financial_company 
SET ID=?,NAME=?,fullname_cn_front=?,shortname_en=?,fullname_en_front=?,CREATE_TIME=?,MODIFY_TIME=?,STATUS=?,PROCESS_STATUS=?,BROKER_COMPANY_ID=?`)
	checkErr(err)
	insertExtend, err := db.Prepare(`INSERT mm_extend_financial_company 
SET id=?,company_id=?,level=?,display_name=?,is_fee=?,description=?,is_internal=?,broker_company_id=?,create_time=?,status=?`)
	checkErr(err)

	dataByte, _ := ioutil.ReadFile("data.txt")
	fileContent := string(dataByte)

	lines := strings.Split(fileContent, "\r\n")

	for _, line := range lines {
		enCnDatas := strings.Split(line, "[")
		if len(enCnDatas) == 2 {
			cnData := strings.Trim(enCnDatas[1], " ")
			cnData = strings.Trim(cnData, "]")
			cnData = strings.Trim(cnData, " ")

			lastIndex := strings.LastIndex(enCnDatas[0], "-")

			var enData = ""
			var enShortData = ""
			if lastIndex != -1 {
				enData = strings.Trim(enCnDatas[0][0:lastIndex], " ")
				enShortData = strings.Trim(enCnDatas[0][lastIndex+1:], " ")
			} else {
				enData = strings.Trim(enCnDatas[0], " ")
			}

			id, err := utils.GenUUID()
			checkErr(err)

			_, err = insertTemp.Exec(id, cnData, cnData, enShortData, enData, "2014-01-01 00:00:00", "2014-01-01 00:00:00", "1", "2", "1")
			checkErr(err)

			_, err = insertExtend.Exec(id, id, 0, cnData, "2", line, "2", "1", "2014-01-01 00:00:00", "1")
			checkErr(err)
		}
	}

}
Exemplo n.º 5
0
func main() {
	m := martini.Classic()
	m.Get("/", func(w http.ResponseWriter, r *http.Request) string {

		cookie, _ := r.Cookie("client_uuid")
		if cookie == nil {
			expiration := time.Now()
			expiration = expiration.AddDate(5, 0, 0)
			uuid, _ := utils.GenUUID()
			cookie = &http.Cookie{Name: "client_uuid", Value: uuid, Expires: expiration}
			http.SetCookie(w, cookie)
		}

		fmt.Println(cookie.Value, r.RemoteAddr)

		return "Hello world!"
	})
	http.ListenAndServe(":7070", m)
}
Exemplo n.º 6
0
func main() {

	db, err := sql.Open("mysql", "artogrid:artogrid@tcp(10.10.2.4:3306)/idb_mm_offline?charset=utf8")
	checkErr(err)

	defer db.Close()

	//删除数据
	stmt, err := db.Prepare("delete from mm_trader_broker_relation where trader_account_id not in (select id from mm_temp_account)")
	checkErr(err)
	_, err = stmt.Exec()
	checkErr(err)

	brokerDataByte, _ := ioutil.ReadFile("broker.txt")
	brokerData := string(brokerDataByte)
	brokerLines := strings.Split(brokerData, "\r\n")

	brokerNameIdMap := make(map[string]string)
	for _, line := range brokerLines {
		brokerNameAndBroker := strings.Split(line, ",")
		name := brokerNameAndBroker[0]
		email := brokerNameAndBroker[1]
		var id []byte
		row := db.QueryRow("select id from idb_center.idb_account where username=?", email)
		row.Scan(&id)
		brokerNameIdMap[name] = string(id)
	}

	companyNameIdMap := make(map[string]string)

	rows, err := db.Query("select name,id from mm_temp_financial_company where broker_company_id=?", brokerCompanyId)
	checkErr(err)

	for rows.Next() {
		var name []byte
		var id []byte
		err = rows.Scan(&name, &id)
		checkErr(err)
		companyNameIdMap[string(name)] = string(id)
	}

	companyNameBrokerIdTraderId := make(map[string]string)
	rows, err = db.Query(`select c.name,r.broker_account_id,t.id 
		from mm_temp_financial_company c,mm_temp_account t,mm_trader_broker_relation r 
		where c.id=t.company_id
		and t.id=r.trader_account_id
		and c.broker_company_id=t.broker_company_id
		and r.broker_company_id=t.broker_company_id
		and c.broker_company_id=?`, brokerCompanyId)
	checkErr(err)

	for rows.Next() {
		var name []byte
		var brokerId []byte
		var traderId []byte
		err = rows.Scan(&name, &brokerId, &traderId)
		checkErr(err)
		companyNameBrokerIdTraderId[string(name)+"_"+string(brokerId)] = string(traderId)
	}

	tx, err := db.Begin()
	checkErr(err)

	//插入机构数据
	insertTemp, err := tx.Prepare(`INSERT mm_temp_financial_company
										SET ID=?,NAME=?,fullname_cn_front=?,CREATE_TIME=?,MODIFY_TIME=?,STATUS=?,PROCESS_STATUS=?,BROKER_COMPANY_ID=?,bank_level=?`)
	checkErr(err)

	insertExtend, err := tx.Prepare(`INSERT mm_extend_financial_company
										SET id=?,company_id=?,level=?,display_name=?,is_fee=?,description=?,is_internal=?,broker_company_id=?,create_time=?,status=?,pinyin=?`)
	checkErr(err)

	//插入trader数据
	insertTraderTemp, err := tx.Prepare(`INSERT mm_temp_account
										SET ID=?,COMPANY_ID=?,COMPANY_NAME=?,ACCOUNT_CODE=?,USERNAME=?,PASSWORD=?,DISPLAY_NAME=?,
										ACCOUNT_TYPE=?,IS_FORBIDDEN=?,CREATE_TIME=?,MODIFY_TIME=?,STATUS=?,process_status=?,broker_company_id=?,pinyin_keyword=?`)
	checkErr(err)

	insertTraderExtend, err := tx.Prepare(`INSERT mm_extend_trader
										SET id=?,account_id=?,display_name=?,broker_company_id=?,create_time=?,status=?`)
	checkErr(err)

	//插入关系数据
	insertRelation, err := tx.Prepare(`INSERT INTO mm_trader_broker_relation 
										(id, trader_account_id, broker_account_id, level, is_temp, create_time, status, broker_company_id) 
										VALUES (?, ?, ?, ?, ?, ?, ?, ?)`)
	checkErr(err)

	dataByte, _ := ioutil.ReadFile("data.txt")
	fileContent := string(dataByte)

	lines := strings.Split(fileContent, "\r\n")

	brokerNameLine := lines[1]
	brokerNamess := strings.Split(brokerNameLine, ",")
	brokerNames := make([]string, len(brokerNamess)/2+1)
	for i, brokerName := range brokerNamess {
		if i%2 == 0 {
			brokerNames[i/2] = brokerName
		}
	}

	n := 30000
	ccc := 0

	for r, line := range lines {
		if r < 3 {
			continue
		}

		nameLevels := strings.Split(line, ",")

		for i := 0; i < len(nameLevels); i = i + 2 {
			cnData := ""
			if i < len(nameLevels) {
				cnData = strings.Trim(nameLevels[i], " ")
			}
			bankLevelCN := ""
			if i+1 < len(nameLevels) {
				bankLevelCN = strings.Trim(nameLevels[i+1], " ")
			}
			if cnData == "" {
				continue
			}

			id, ok := companyNameIdMap[cnData]
			if !ok {

				bankLevel := levelMap[bankLevelCN]

				id, err = utils.GenUUID()
				checkErr(err)

				_, err = insertTemp.Exec(id, cnData, cnData, createTime, createTime, status, processStatus, brokerCompanyId, bankLevel)
				checkErr(err)

				_, err = insertExtend.Exec(id, id, 1, cnData, isFee, cnData, isInternal, brokerCompanyId, createTime, status, toPinyin(cnData))
				checkErr(err)

				companyNameIdMap[cnData] = id

				fmt.Println(cnData, bankLevelCN)
			}

			brokerName := brokerNames[i/2]
			brokerId := brokerNameIdMap[brokerName]
			_, ok = companyNameBrokerIdTraderId[cnData+"_"+brokerId]
			if !ok {
				traderId, err := utils.GenUUID()
				checkErr(err)
				traderName := fmt.Sprintf("trader%v", n)
				n++

				_, err = insertTraderTemp.Exec(traderId, id, cnData, traderName, traderName, "123456", traderName, "2", "1", createTime, createTime, status, processStatus, brokerCompanyId, traderName)
				checkErr(err)

				_, err = insertTraderExtend.Exec(traderId, traderId, traderName, brokerCompanyId, createTime, "1")
				checkErr(err)

				relationId, err := utils.GenUUID()
				checkErr(err)

				_, err = insertRelation.Exec(relationId, traderId, brokerId, 0, "", createTime, status, brokerCompanyId)
				checkErr(err)

				fmt.Println(cnData, bankLevelCN, brokerName)

				ccc++
			}
		}
	}

	tx.Commit()

	fmt.Println(ccc)
}