Browse Source

省市区server

wangxingcheng 3 years ago
parent
commit
a93c6560a3

+ 36 - 0
opms_parent/app/dao/base/base_district.go

@@ -0,0 +1,36 @@
+// ============================================================================
+// This is auto-generated by gf cli tool only once. Fill this file as you wish.
+// ============================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/dao/base/internal"
+)
+
+// baseDistrictDao is the manager for logic model data accessing
+// and custom defined data operations functions management. You can define
+// methods on it to extend its functionality as you wish.
+type baseDistrictDao struct {
+	internal.BaseDistrictDao
+}
+
+var (
+	// BaseDistrict is globally public accessible object for table base_district operations.
+	BaseDistrict = baseDistrictDao{
+		internal.BaseDistrict,
+	}
+)
+
+type BaseDistrictDao struct {
+	internal.BaseDistrictDao
+}
+
+func NewBaseDistrictDao(tenant string) *BaseDistrictDao {
+	dao := internal.NewBaseDistrictDao(tenant)
+	return &BaseDistrictDao{
+		dao,
+	}
+}
+
+// Fill with you ideas below.

+ 438 - 0
opms_parent/app/dao/base/internal/base_district.go

@@ -0,0 +1,438 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"context"
+	"database/sql"
+	"github.com/gogf/gf/database/gdb"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/frame/gmvc"
+	"time"
+
+	"dashoo.cn/micro/app/model"
+)
+
+// BaseDistrictDao is the manager for logic model data accessing
+// and custom defined data operations functions management.
+type BaseDistrictDao struct {
+	gmvc.M
+	DB      gdb.DB
+	Table   string
+	Columns baseDistrictColumns
+}
+
+// BaseDistrictColumns defines and stores column names for table base_district.
+type baseDistrictColumns struct {
+	Id            string // 主键
+	DistName      string // 地区名称
+	DistShortName string // 地区简称
+	DistCode      string // 地区编号
+	DistLevel     string // 地区级别;1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县
+	ParentId      string // 上级编码
+	Path          string // 路径
+	Remark        string // 备注
+	CreatedBy     string // 创建者
+	CreatedName   string // 创建人
+	CreatedTime   string // 创建时间
+	UpdatedBy     string // 更新者
+	UpdatedName   string // 更新人
+	UpdatedTime   string // 更新时间
+	DeletedTime   string // 删除时间
+}
+
+var (
+	// BaseDistrict is globally public accessible object for table base_district operations.
+	BaseDistrict = BaseDistrictDao{
+		M:     g.DB("default").Model("base_district").Safe(),
+		DB:    g.DB("default"),
+		Table: "base_district",
+		Columns: baseDistrictColumns{
+			Id:            "id",
+			DistName:      "dist_name",
+			DistShortName: "dist_short_name",
+			DistCode:      "dist_code",
+			DistLevel:     "dist_level",
+			ParentId:      "parent_id",
+			Path:          "path",
+			Remark:        "remark",
+			CreatedBy:     "created_by",
+			CreatedName:   "created_name",
+			CreatedTime:   "created_time",
+			UpdatedBy:     "updated_by",
+			UpdatedName:   "updated_name",
+			UpdatedTime:   "updated_time",
+			DeletedTime:   "deleted_time",
+		},
+	}
+)
+
+func NewBaseDistrictDao(tenant string) BaseDistrictDao {
+	var dao BaseDistrictDao
+	dao = BaseDistrictDao{
+		M:     g.DB(tenant).Model("base_district").Safe(),
+		DB:    g.DB(tenant),
+		Table: "base_district",
+		Columns: baseDistrictColumns{
+			Id:            "id",
+			DistName:      "dist_name",
+			DistShortName: "dist_short_name",
+			DistCode:      "dist_code",
+			DistLevel:     "dist_level",
+			ParentId:      "parent_id",
+			Path:          "path",
+			Remark:        "remark",
+			CreatedBy:     "created_by",
+			CreatedName:   "created_name",
+			CreatedTime:   "created_time",
+			UpdatedBy:     "updated_by",
+			UpdatedName:   "updated_name",
+			UpdatedTime:   "updated_time",
+			DeletedTime:   "deleted_time",
+		},
+	}
+	return dao
+}
+
+// Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
+// of current DB object and with given context in it.
+// Note that this returned DB object can be used only once, so do not assign it to
+// a global or package variable for long using.
+func (d *BaseDistrictDao) Ctx(ctx context.Context) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Ctx(ctx)}
+}
+
+// As sets an alias name for current table.
+func (d *BaseDistrictDao) As(as string) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (d *BaseDistrictDao) TX(tx *gdb.TX) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (d *BaseDistrictDao) Master() *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Master()}
+}
+
+// Slave marks the following operation on slave node.
+// Note that it makes sense only if there's any slave node configured.
+func (d *BaseDistrictDao) Slave() *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Slave()}
+}
+
+// Args sets custom arguments for model operation.
+func (d *BaseDistrictDao) Args(args ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Args(args...)}
+}
+
+// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistrictDao) LeftJoin(table ...string) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.LeftJoin(table...)}
+}
+
+// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistrictDao) RightJoin(table ...string) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.RightJoin(table...)}
+}
+
+// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
+// The parameter <table> can be joined table and its joined condition,
+// and also with its alias name, like:
+// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
+// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
+func (d *BaseDistrictDao) InnerJoin(table ...string) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.InnerJoin(table...)}
+}
+
+// Fields sets the operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistrictDao) Fields(fieldNamesOrMapStruct ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
+}
+
+// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
+// The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
+func (d *BaseDistrictDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
+}
+
+// Option sets the extra operation option for the model.
+func (d *BaseDistrictDao) Option(option int) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Option(option)}
+}
+
+// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
+// the data and where attributes for empty values.
+func (d *BaseDistrictDao) OmitEmpty() *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (d *BaseDistrictDao) Filter() *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Filter()}
+}
+
+// Where sets the condition statement for the model. The parameter <where> can be type of
+// string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
+// multiple conditions will be joined into where statement using "AND".
+// Eg:
+// Where("uid=10000")
+// Where("uid", 10000)
+// Where("money>? AND name like ?", 99999, "vip_%")
+// Where("uid", 1).Where("name", "john")
+// Where("status IN (?)", g.Slice{1,2,3})
+// Where("age IN(?,?)", 18, 50)
+// Where(User{ Id : 1, UserName : "john"})
+func (d *BaseDistrictDao) Where(where interface{}, args ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Where(where, args...)}
+}
+
+// WherePri does the same logic as M.Where except that if the parameter <where>
+// is a single condition like int/string/float/slice, it treats the condition as the primary
+// key value. That is, if primary key is "id" and given <where> parameter as "123", the
+// WherePri function treats the condition as "id=123", but M.Where treats the condition
+// as string "123".
+func (d *BaseDistrictDao) WherePri(where interface{}, args ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.WherePri(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (d *BaseDistrictDao) And(where interface{}, args ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (d *BaseDistrictDao) Or(where interface{}, args ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *BaseDistrictDao) Group(groupBy string) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *BaseDistrictDao) Order(orderBy ...string) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Order(orderBy...)}
+}
+
+// Limit sets the "LIMIT" statement for the model.
+// The parameter <limit> can be either one or two number, if passed two number is passed,
+// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
+// statement.
+func (d *BaseDistrictDao) Limit(limit ...int) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Limit(limit...)}
+}
+
+// Offset sets the "OFFSET" statement for the model.
+// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
+func (d *BaseDistrictDao) Offset(offset int) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Offset(offset)}
+}
+
+// Page sets the paging number for the model.
+// The parameter <page> is started from 1 for paging.
+// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
+func (d *BaseDistrictDao) Page(page, limit int) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *BaseDistrictDao) Batch(batch int) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Batch(batch)}
+}
+
+// Cache sets the cache feature for the model. It caches the result of the sql, which means
+// if there's another same sql request, it just reads and returns the result from cache, it
+// but not committed and executed into the database.
+//
+// If the parameter <duration> < 0, which means it clear the cache with given <name>.
+// If the parameter <duration> = 0, which means it never expires.
+// If the parameter <duration> > 0, which means it expires after <duration>.
+//
+// The optional parameter <name> is used to bind a name to the cache, which means you can later
+// control the cache like changing the <duration> or clearing the cache with specified <name>.
+//
+// Note that, the cache feature is disabled if the model is operating on a transaction.
+func (d *BaseDistrictDao) Cache(duration time.Duration, name ...string) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Cache(duration, name...)}
+}
+
+// Data sets the operation data for the model.
+// The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
+// Eg:
+// Data("uid=10000")
+// Data("uid", 10000)
+// Data(g.Map{"uid": 10000, "name":"john"})
+// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
+func (d *BaseDistrictDao) Data(data ...interface{}) *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Data(data...)}
+}
+
+// All does "SELECT FROM ..." statement for the model.
+// It retrieves the records from table and returns the result as []*model.BaseDistrict.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistrictDao) All(where ...interface{}) ([]*model.BaseDistrict, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistrict
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// One retrieves one record from table and returns the result as *model.BaseDistrict.
+// It returns nil if there's no record retrieved with the given conditions from table.
+//
+// The optional parameter <where> is the same as the parameter of M.Where function,
+// see M.Where.
+func (d *BaseDistrictDao) One(where ...interface{}) (*model.BaseDistrict, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistrict
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindOne retrieves and returns a single Record by M.WherePri and M.One.
+// Also see M.WherePri and M.One.
+func (d *BaseDistrictDao) FindOne(where ...interface{}) (*model.BaseDistrict, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseDistrict
+	if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entity, nil
+}
+
+// FindAll retrieves and returns Result by by M.WherePri and M.All.
+// Also see M.WherePri and M.All.
+func (d *BaseDistrictDao) FindAll(where ...interface{}) ([]*model.BaseDistrict, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseDistrict
+	if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
+		return nil, err
+	}
+	return entities, nil
+}
+
+// Struct retrieves one record from table and converts it into given struct.
+// The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
+// it can create the struct internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not nil.
+//
+// Eg:
+// user := new(User)
+// err  := dao.User.Where("id", 1).Struct(user)
+//
+// user := (*User)(nil)
+// err  := dao.User.Where("id", 1).Struct(&user)
+func (d *BaseDistrictDao) Struct(pointer interface{}, where ...interface{}) error {
+	return d.M.Struct(pointer, where...)
+}
+
+// Structs retrieves records from table and converts them into given struct slice.
+// The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
+// slice internally during converting.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
+// from table and <pointer> is not empty.
+//
+// Eg:
+// users := ([]User)(nil)
+// err   := dao.User.Structs(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Structs(&users)
+func (d *BaseDistrictDao) Structs(pointer interface{}, where ...interface{}) error {
+	return d.M.Structs(pointer, where...)
+}
+
+// Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
+// It calls function Struct if <pointer> is type of *struct/**struct.
+// It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
+//
+// The optional parameter <where> is the same as the parameter of Model.Where function,
+// see Model.Where.
+//
+// Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
+//
+// Eg:
+// user  := new(User)
+// err   := dao.User.Where("id", 1).Scan(user)
+//
+// user  := (*User)(nil)
+// err   := dao.User.Where("id", 1).Scan(&user)
+//
+// users := ([]User)(nil)
+// err   := dao.User.Scan(&users)
+//
+// users := ([]*User)(nil)
+// err   := dao.User.Scan(&users)
+func (d *BaseDistrictDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *BaseDistrictDao) Chunk(limit int, callback func(entities []*model.BaseDistrict, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*model.BaseDistrict
+		err = result.Structs(&entities)
+		if err == sql.ErrNoRows {
+			return false
+		}
+		return callback(entities, err)
+	})
+}
+
+// LockUpdate sets the lock for update for current operation.
+func (d *BaseDistrictDao) LockUpdate() *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.LockUpdate()}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *BaseDistrictDao) LockShared() *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.LockShared()}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *BaseDistrictDao) Unscoped() *BaseDistrictDao {
+	return &BaseDistrictDao{M: d.M.Unscoped()}
+}

+ 14 - 0
opms_parent/app/model/base/base_district.go

@@ -0,0 +1,14 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. Fill this file as you wish.
+// ==========================================================================
+
+package base
+
+import (
+	"dashoo.cn/micro/app/model/base/internal"
+)
+
+// BaseDistrict is the golang structure for table base_district.
+type BaseDistrict internal.BaseDistrict
+
+// Fill with you ideas below.

+ 28 - 0
opms_parent/app/model/base/internal/base_district.go

@@ -0,0 +1,28 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
+// ==========================================================================
+
+package internal
+
+import (
+	"github.com/gogf/gf/os/gtime"
+)
+
+// BaseDistrict is the golang structure for table base_district.
+type BaseDistrict struct {
+	Id            int         `orm:"id,primary"      json:"id"`            // 主键
+	DistName      string      `orm:"dist_name"       json:"distName"`      // 地区名称
+	DistShortName string      `orm:"dist_short_name" json:"distShortName"` // 地区简称
+	DistCode      string      `orm:"dist_code"       json:"distCode"`      // 地区编号
+	DistLevel     string      `orm:"dist_level"      json:"distLevel"`     // 地区级别;1-省、自治区、直辖市 2-地级市、地区、自治州、盟 3-市辖区、县级市、县
+	ParentId      int         `orm:"parent_id"       json:"parentId"`      // 上级编码
+	Path          string      `orm:"path"            json:"path"`          // 路径
+	Remark        string      `orm:"remark"          json:"remark"`        // 备注
+	CreatedBy     int         `orm:"created_by"      json:"createdBy"`     // 创建者
+	CreatedName   string      `orm:"created_name"    json:"createdName"`   // 创建人
+	CreatedTime   *gtime.Time `orm:"created_time"    json:"createdTime"`   // 创建时间
+	UpdatedBy     int         `orm:"updated_by"      json:"updatedBy"`     // 更新者
+	UpdatedName   string      `orm:"updated_name"    json:"updatedName"`   // 更新人
+	UpdatedTime   *gtime.Time `orm:"updated_time"    json:"updatedTime"`   // 更新时间
+	DeletedTime   *gtime.Time `orm:"deleted_time"    json:"deletedTime"`   // 删除时间
+}

+ 47 - 0
opms_parent/app/service/base/base_district.go

@@ -0,0 +1,47 @@
+package base
+
+import (
+	"context"
+
+	"github.com/gogf/gf/frame/g"
+
+	"dashoo.cn/micro/app/dao/base"
+	model "dashoo.cn/micro/app/model/base"
+	"dashoo.cn/micro/app/service"
+)
+
+type districtService struct {
+	*service.ContextService
+
+	Dao *base.BaseDistrictDao
+}
+
+func NewDistrictService(ctx context.Context) (svc *districtService, err error) {
+	svc = new(districtService)
+	if svc.ContextService, err = svc.Init(ctx); err != nil {
+		return nil, err
+	}
+	svc.Dao = base.NewBaseDistrictDao(svc.Tenant)
+	return svc, nil
+}
+
+//区域省市区 树形结构
+func (d *districtService) ListToTree(pid int) []*model.T {
+	var distributorList []model.BaseDistrict
+	d.Dao.M.Where(base.BaseDistrict.Columns.ParentId, pid).Scan(&distributorList)
+	treeList := []*model.T{}
+	for _, v := range distributorList {
+		if v.ParentId == pid {
+			child := d.ListToTree(v.Id)
+			node := &model.T{
+				Id:       v.Id,
+				ParentId: v.ParentId,
+				DistName: v.DistName,
+			}
+			node.Children = child
+			treeList = append(treeList, node)
+		}
+	}
+	g.Log().Info("xc11", treeList)
+	return treeList
+}