- initData.InitPlace.
This commit is contained in:
106
business/jxstore/initdata/initdata.go
Normal file
106
business/jxstore/initdata/initdata.go
Normal file
@@ -0,0 +1,106 @@
|
||||
package initdata
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/autonavi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
)
|
||||
|
||||
func TruncateTable(db *dao.DaoDB, tableName string) (err error) {
|
||||
_, err = dao.ExecuteSQL(db, "TRUNCATE TABLE "+tableName)
|
||||
return err
|
||||
}
|
||||
|
||||
func insertPlace(ctx *jxcontext.Context, db *dao.DaoDB, parent *autonavi.District, placeList []*autonavi.District) (err error) {
|
||||
for _, v := range placeList {
|
||||
if v.Level <= autonavi.DistrictLevelDistrict {
|
||||
place := &model.Place{
|
||||
Code: int(utils.Str2Int64(v.Adcode)),
|
||||
Name: v.Name,
|
||||
Level: int8(v.Level),
|
||||
TelCode: v.Citycode,
|
||||
}
|
||||
if parent != nil {
|
||||
place.ParentCode = int(utils.Str2Int64(parent.Adcode))
|
||||
}
|
||||
dao.WrapAddIDCULEntity(place, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, place); err != nil {
|
||||
return err
|
||||
}
|
||||
if err = insertPlace(ctx, db, v, v.Districts); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func InitPlace(ctx *jxcontext.Context) (err error) {
|
||||
db := dao.GetDB()
|
||||
if err = TruncateTable(db, "place"); err == nil {
|
||||
placeList, err2 := api.AutonaviAPI.GetDistricts(autonavi.DistrictLevelDistrict, "")
|
||||
if err = err2; err != nil {
|
||||
return err
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
dao.Rollback(db)
|
||||
}()
|
||||
if err = insertPlace(ctx, db, nil, placeList); err != nil {
|
||||
return err
|
||||
}
|
||||
updateSqls := []string{
|
||||
`
|
||||
UPDATE place t1
|
||||
JOIN jde_city t2 ON t1.code = t2.col_tencentAddressCode
|
||||
SET t1.jd_code = t2.col_areaCode;
|
||||
`,
|
||||
`
|
||||
UPDATE place t1
|
||||
JOIN place t2 ON t1.parent_code = t2.code AND t2.jd_code != 0
|
||||
JOIN jde_district t3 ON t1.name = t3.col_areaName AND t2.jd_code = t3.col_cityCode
|
||||
SET t1.jd_code = t3.col_areaCode
|
||||
WHERE t1.level = 3;
|
||||
`,
|
||||
`
|
||||
UPDATE
|
||||
place t1
|
||||
JOIN ebde_places t2 ON t1.name = t2.col_city_name
|
||||
SET t1.ebai_code = t2.col_city_id
|
||||
WHERE t1.level = 1 OR t1.level = 2;
|
||||
`,
|
||||
`
|
||||
UPDATE
|
||||
place t1
|
||||
JOIN place t1p ON t1.parent_code = t1p.code
|
||||
JOIN ebde_places t2 ON t1.name = t2.col_city_name
|
||||
JOIN ebde_places t2p ON t2.col_parent_id = t2p.col_city_id AND t1p.ebai_code = t2p.col_city_id
|
||||
SET t1.ebai_code = t2.col_city_id
|
||||
WHERE t1.level = 3;
|
||||
`,
|
||||
`
|
||||
UPDATE
|
||||
place t1
|
||||
JOIN mtpsdeliveryprice t2 ON t1.code = t2.citycode
|
||||
SET t1.mtps_price = t2.price;
|
||||
`,
|
||||
`
|
||||
UPDATE
|
||||
place t1
|
||||
JOIN mtpsdeliveryprice t2 ON t1.name LIKE CONCAT(t2.cityname, '%')
|
||||
SET t1.mtps_price = t2.price
|
||||
WHERE t1.level = 2 AND t1.mtps_price = 0;
|
||||
`,
|
||||
}
|
||||
for _, v := range updateSqls {
|
||||
if _, err = dao.ExecuteSQL(db, v); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
return err
|
||||
}
|
||||
23
controllers/init_data.go
Normal file
23
controllers/init_data.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/initdata"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type InitDataController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// @Title 初始化place信息
|
||||
// @Description 初始化place信息,要求:jde_city, jde_district, ebde_places, mtpsdeliveryprice
|
||||
// @Param token header string true "认证token"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /InitPlace [post]
|
||||
func (c *InitDataController) InitPlace() {
|
||||
c.callInitPlace(func(params *tInitdataInitPlaceParams) (retVal interface{}, errCode string, err error) {
|
||||
err = initdata.InitPlace(params.Ctx)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -127,6 +127,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:InitDataController"],
|
||||
beego.ControllerComments{
|
||||
Method: "InitPlace",
|
||||
Router: `/InitPlace`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateWaybillOnProviders",
|
||||
|
||||
@@ -71,6 +71,11 @@ func init() {
|
||||
&controllers.SyncController{},
|
||||
),
|
||||
),
|
||||
beego.NSNamespace("/initdata",
|
||||
beego.NSInclude(
|
||||
&controllers.InitDataController{},
|
||||
),
|
||||
),
|
||||
)
|
||||
beego.AddNamespace(ns)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user