Commit f8941d1b by dliangx

update

parent 7bca95c7
......@@ -99,6 +99,15 @@ func SaveOptArea(optArea model.GeoJson) (model.OptArea, error) {
area.OptTime = time.Now()
area.Geometry = optArea.Geometry
area.Properties = optArea.Properties
optArea.Opt = 4
relatedArea, err := GetRelatedAdmArea(optArea)
if err == nil {
for key, value := range relatedArea[0].Properties {
area.Properties[key] = value
}
}
return area, nil
}
......@@ -187,6 +196,15 @@ func UpdateOptArea(optArea model.GeoJson) (model.OptArea, error) {
area.OptTime = time.Now()
area.Geometry = optArea.Geometry
area.Properties = optArea.Properties
optArea.Opt = 4
relatedArea, err := GetRelatedAdmArea(optArea)
if err == nil {
for key, value := range relatedArea[0].Properties {
area.Properties[key] = value
}
}
return area, nil
}
......@@ -472,10 +490,10 @@ func CalcAreasCenter(ids []string, opt int) (float64, float64, error) {
}
err = db.QueryRow(query).Scan(&wktPoint)
if err != nil {
if err == sql.ErrNoRows {
if wktPoint == "" {
return 0, 0, fmt.Errorf("no areas found")
}
if err != nil {
return 0, 0, fmt.Errorf("calculate center failed: %w", err)
}
......
......@@ -45,7 +45,7 @@ func ProcessGeoJSONFile(filename string) error {
}
func connectDB() (*sql.DB, error) {
connStr := "postgres://liang:postgres@localhost/xpolt?sslmode=disable"
connStr := "postgres://postgres:postgres@localhost/xpolt?sslmode=disable"
return sql.Open("postgres", connStr)
}
......
......@@ -25,7 +25,7 @@ func SaveGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10001, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else if req.Opt == 3 {
resp, err := geo.SaveOptArea(req)
......@@ -33,7 +33,7 @@ func SaveGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10002, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else {
c.JSON(consts.StatusBadRequest, utils.H{"message": "opt value is not allow"})
......@@ -54,7 +54,7 @@ func UpdateGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10003, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else if req.Opt == 3 {
resp, err := geo.UpdateOptArea(req)
......@@ -62,7 +62,7 @@ func UpdateGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10004, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else {
c.JSON(consts.StatusBadRequest, utils.H{"message": "opt value is not allow"})
......@@ -91,7 +91,7 @@ func GetGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10005, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else if opt == 3 {
resp, err := geo.GetOptArea(id, opt)
......@@ -99,7 +99,7 @@ func GetGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10006, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else {
c.JSON(consts.StatusBadRequest, utils.H{"message": "opt value is not allow"})
......@@ -127,7 +127,7 @@ func DeleteGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10007, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else if opt == 3 {
resp, err := geo.DeleteOptArea(id, opt)
......@@ -135,7 +135,7 @@ func DeleteGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10008, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else {
c.JSON(consts.StatusBadRequest, utils.H{"message": "opt value is not allow"})
......@@ -155,7 +155,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10009, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else if req.Opt == 3 {
resp, err := geo.GetRelatedOptArea(req)
......@@ -163,7 +163,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10010, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else if req.Opt == 4 {
resp, err := geo.GetRelatedAdmArea(req)
......@@ -171,7 +171,7 @@ func FindRelatedGeometry(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10010, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, resp)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": resp})
return
} else {
c.JSON(consts.StatusBadRequest, utils.H{"message": "opt value is not allow"})
......@@ -231,6 +231,6 @@ func CheckTwoOptAreaIsCross(ctx context.Context, c *app.RequestContext) {
c.JSON(consts.StatusOK, utils.H{"code": 10011, "message": err.Error()})
return
}
c.JSON(consts.StatusOK, res)
c.JSON(consts.StatusOK, utils.H{"code": 200, "data": res})
}
......@@ -13,8 +13,8 @@ import (
)
func main() {
//filename := "/Users/liang/Downloads/山西省村界.geojson"
// geo.ProcessGeoJSONFile(filename)
//filename := "/Users/liang/Downloads/山西省村界.geojson"
h := server.Default(
server.WithHostPorts(":8686"),
)
......
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