浏览代码

freature(产品线): 产品线授权功能实现

likai 2 年之前
父节点
当前提交
6691846b59

+ 36 - 0
opms_admin/app/dao/base_product_auth.go

@@ -0,0 +1,36 @@
+// ============================================================================
+// This is auto-generated by gf cli tool only once. Fill this file as you wish.
+// ============================================================================
+
+package dao
+
+import (
+	"dashoo.cn/micro/app/dao/internal"
+)
+
+// baseProductAuthDao 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 baseProductAuthDao struct {
+	internal.BaseProductAuthDao
+}
+
+var (
+	// BaseProductAuth is globally public accessible object for table base_product_auth operations.
+	BaseProductAuth = baseProductAuthDao{
+		internal.BaseProductAuth,
+	}
+)
+
+type BaseProductAuthDao struct {
+	internal.BaseProductAuthDao
+}
+
+func NewBaseProductAuthDao(tenant string) *BaseProductAuthDao {
+	dao := internal.NewBaseProductAuthDao(tenant)
+	return &BaseProductAuthDao{
+		dao,
+	}
+}
+
+// Fill with you ideas below.

+ 438 - 0
opms_admin/app/dao/internal/base_product_auth.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"
+)
+
+// BaseProductAuthDao is the manager for logic model data accessing
+// and custom defined data operations functions management.
+type BaseProductAuthDao struct {
+	gmvc.M
+	DB      gdb.DB
+	Table   string
+	Columns baseProductAuthColumns
+}
+
+// BaseProductAuthColumns defines and stores column names for table base_product_auth.
+type baseProductAuthColumns struct {
+	Id          string // 主键
+	UserId      string // 用户ID
+	UserName    string // 用户姓名
+	UserPost    string // 岗位
+	UserPhone   string // 电话
+	ProductCode string // 产品线编码
+	ProductName string // 产品线名称
+	Remark      string // 备注
+	CreatedBy   string // 创建者
+	CreatedName string // 创建人
+	CreatedTime string // 创建时间
+	UpdatedBy   string // 更新者
+	UpdatedName string // 更新人
+	UpdatedTime string // 更新时间
+	DeletedTime string // 删除时间
+}
+
+var (
+	// BaseProductAuth is globally public accessible object for table base_product_auth operations.
+	BaseProductAuth = BaseProductAuthDao{
+		M:     g.DB("default").Model("base_product_auth").Safe(),
+		DB:    g.DB("default"),
+		Table: "base_product_auth",
+		Columns: baseProductAuthColumns{
+			Id:          "id",
+			UserId:      "user_id",
+			UserName:    "user_name",
+			UserPost:    "user_post",
+			UserPhone:   "user_phone",
+			ProductCode: "product_code",
+			ProductName: "product_name",
+			Remark:      "remark",
+			CreatedBy:   "created_by",
+			CreatedName: "created_name",
+			CreatedTime: "created_time",
+			UpdatedBy:   "updated_by",
+			UpdatedName: "updated_name",
+			UpdatedTime: "updated_time",
+			DeletedTime: "deleted_time",
+		},
+	}
+)
+
+func NewBaseProductAuthDao(tenant string) BaseProductAuthDao {
+	var dao BaseProductAuthDao
+	dao = BaseProductAuthDao{
+		M:     g.DB(tenant).Model("base_product_auth").Safe(),
+		DB:    g.DB(tenant),
+		Table: "base_product_auth",
+		Columns: baseProductAuthColumns{
+			Id:          "id",
+			UserId:      "user_id",
+			UserName:    "user_name",
+			UserPost:    "user_post",
+			UserPhone:   "user_phone",
+			ProductCode: "product_code",
+			ProductName: "product_name",
+			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 *BaseProductAuthDao) Ctx(ctx context.Context) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.Ctx(ctx)}
+}
+
+// As sets an alias name for current table.
+func (d *BaseProductAuthDao) As(as string) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.As(as)}
+}
+
+// TX sets the transaction for current operation.
+func (d *BaseProductAuthDao) TX(tx *gdb.TX) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.TX(tx)}
+}
+
+// Master marks the following operation on master node.
+func (d *BaseProductAuthDao) Master() *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Slave() *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.Slave()}
+}
+
+// Args sets custom arguments for model operation.
+func (d *BaseProductAuthDao) Args(args ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) LeftJoin(table ...string) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) RightJoin(table ...string) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) InnerJoin(table ...string) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Fields(fieldNamesOrMapStruct ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
+}
+
+// Option sets the extra operation option for the model.
+func (d *BaseProductAuthDao) Option(option int) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) OmitEmpty() *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.OmitEmpty()}
+}
+
+// Filter marks filtering the fields which does not exist in the fields of the operated table.
+func (d *BaseProductAuthDao) Filter() *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Where(where interface{}, args ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) WherePri(where interface{}, args ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.WherePri(where, args...)}
+}
+
+// And adds "AND" condition to the where statement.
+func (d *BaseProductAuthDao) And(where interface{}, args ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.And(where, args...)}
+}
+
+// Or adds "OR" condition to the where statement.
+func (d *BaseProductAuthDao) Or(where interface{}, args ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.Or(where, args...)}
+}
+
+// Group sets the "GROUP BY" statement for the model.
+func (d *BaseProductAuthDao) Group(groupBy string) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.Group(groupBy)}
+}
+
+// Order sets the "ORDER BY" statement for the model.
+func (d *BaseProductAuthDao) Order(orderBy ...string) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Limit(limit ...int) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Offset(offset int) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Page(page, limit int) *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.Page(page, limit)}
+}
+
+// Batch sets the batch operation number for the model.
+func (d *BaseProductAuthDao) Batch(batch int) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Cache(duration time.Duration, name ...string) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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 *BaseProductAuthDao) Data(data ...interface{}) *BaseProductAuthDao {
+	return &BaseProductAuthDao{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.BaseProductAuth.
+// 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 *BaseProductAuthDao) All(where ...interface{}) ([]*model.BaseProductAuth, error) {
+	all, err := d.M.All(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseProductAuth
+	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.BaseProductAuth.
+// 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 *BaseProductAuthDao) One(where ...interface{}) (*model.BaseProductAuth, error) {
+	one, err := d.M.One(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseProductAuth
+	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 *BaseProductAuthDao) FindOne(where ...interface{}) (*model.BaseProductAuth, error) {
+	one, err := d.M.FindOne(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entity *model.BaseProductAuth
+	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 *BaseProductAuthDao) FindAll(where ...interface{}) ([]*model.BaseProductAuth, error) {
+	all, err := d.M.FindAll(where...)
+	if err != nil {
+		return nil, err
+	}
+	var entities []*model.BaseProductAuth
+	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 *BaseProductAuthDao) 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 *BaseProductAuthDao) 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 *BaseProductAuthDao) Scan(pointer interface{}, where ...interface{}) error {
+	return d.M.Scan(pointer, where...)
+}
+
+// Chunk iterates the table with given size and callback function.
+func (d *BaseProductAuthDao) Chunk(limit int, callback func(entities []*model.BaseProductAuth, err error) bool) {
+	d.M.Chunk(limit, func(result gdb.Result, err error) bool {
+		var entities []*model.BaseProductAuth
+		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 *BaseProductAuthDao) LockUpdate() *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.LockUpdate()}
+}
+
+// LockShared sets the lock in share mode for current operation.
+func (d *BaseProductAuthDao) LockShared() *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.LockShared()}
+}
+
+// Unscoped enables/disables the soft deleting feature.
+func (d *BaseProductAuthDao) Unscoped() *BaseProductAuthDao {
+	return &BaseProductAuthDao{M: d.M.Unscoped()}
+}

+ 64 - 0
opms_admin/app/handler/base_product_auth.go

@@ -0,0 +1,64 @@
+package handler
+
+import (
+	"context"
+	"errors"
+	"github.com/gogf/gf/util/gvalid"
+
+	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/micro/app/model"
+	"dashoo.cn/micro/app/service"
+	"github.com/gogf/gf/frame/g"
+)
+
+type BaseProductAuthHandler struct{}
+
+// GetList 获取列表
+func (h *BaseProductAuthHandler) GetList(ctx context.Context, req *model.BaseProductAuthSearchReq, rsp *comm_def.CommonMsg) error {
+	lineService, err := service.NewLineService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return errors.New("系统异常,请重新尝试")
+	}
+	total, list, err := lineService.GetList(req)
+	if err != nil {
+		return err
+	}
+	rsp.Data = g.Map{"list": list, "total": total}
+	return nil
+}
+
+// Save 保存数据
+func (h *BaseProductAuthHandler) Save(ctx context.Context, req *model.SaveBaseProductAuthReq, rsp *comm_def.CommonMsg) (err error) {
+	// 检查请求参数
+	if v := gvalid.CheckStruct(ctx, req, nil); v != nil {
+		return v
+	}
+	// 检查列表数据
+	for _, line := range req.Lines {
+		if v := gvalid.CheckStruct(ctx, line, nil); v != nil {
+			return v
+		}
+	}
+	lineService, err := service.NewLineService(ctx)
+	if err != nil {
+		return err
+	}
+	err = lineService.Save(req)
+	return err
+}
+
+// GetProductLineUsers 获取列表
+func (h *BaseProductAuthHandler) GetProductLineUsers(ctx context.Context, req *model.SysUserSearchReq, rsp *comm_def.CommonMsg) error {
+	lineService, err := service.NewLineService(ctx)
+	if err != nil {
+		g.Log().Error(err)
+		return errors.New("系统异常,请重新尝试")
+	}
+	total, list, err := lineService.GetProductLineUsers(req)
+	if err != nil {
+		return err
+	}
+	rsp.Data = g.Map{"list": list, "total": total}
+	return nil
+}

+ 42 - 0
opms_admin/app/model/base_product_auth.go

@@ -0,0 +1,42 @@
+// ==========================================================================
+// This is auto-generated by gf cli tool. Fill this file as you wish.
+// ==========================================================================
+
+package model
+
+import (
+	"dashoo.cn/micro/app/model/internal"
+	"dashoo.cn/opms_libary/request"
+)
+
+// BaseProductAuth is the golang structure for table base_product_auth.
+type BaseProductAuth internal.BaseProductAuth
+
+// Fill with you ideas below.
+
+// BaseProductAuthSearchReq 产品线受权查询
+type BaseProductAuthSearchReq struct {
+	UserId      int    `orm:"user_id"      json:"userId"`      // 用户ID
+	UserName    string `orm:"user_name"    json:"userName"`    // 用户姓名
+	UserPost    string `orm:"user_post"    json:"userPost"`    // 岗位
+	UserPhone   string `orm:"user_phone"   json:"userPhone"`   // 电话
+	ProductCode string `orm:"product_code" json:"productCode"` // 产品线编码
+	ProductName string `orm:"product_name" json:"productName"` // 产品线名称
+	request.PageReq
+}
+
+// SaveBaseProductAuthReq 产品线更新
+type SaveBaseProductAuthReq struct {
+	UserId    int            `orm:"user_id"      json:"userId"      v:"required|min:1#用户ID不能为空|用户ID不能为空"` // 用户ID
+	UserName  string         `orm:"user_name"    json:"userName"    v:"required#用户姓名不能为空"`                    // 用户姓名
+	UserPost  string         `orm:"user_post"    json:"userPost"`                                                     // 岗位
+	UserPhone string         `orm:"user_phone"   json:"userPhone"`                                                    // 电话
+	Lines     []*ProductLine `json:"lines"    v:"required#产品线不能为空"`
+}
+
+// ProductLine 产品线
+type ProductLine struct {
+	ProductCode string `orm:"product_code" json:"productCode" v:"required#产品线编码不能为空"` // 产品线编码
+	ProductName string `orm:"product_name" json:"productName" v:"required#产品线名称不能为空"` // 产品线名称
+	Remark      string `orm:"remark"       json:"remark"`                                      // 备注
+}

+ 28 - 0
opms_admin/app/model/internal/base_product_auth.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"
+)
+
+// BaseProductAuth is the golang structure for table base_product_auth.
+type BaseProductAuth struct {
+	Id          int         `orm:"id,primary"   json:"id"`          // 主键
+	UserId      int         `orm:"user_id"      json:"userId"`      // 用户ID
+	UserName    string      `orm:"user_name"    json:"userName"`    // 用户姓名
+	UserPost    string      `orm:"user_post"    json:"userPost"`    // 岗位
+	UserPhone   string      `orm:"user_phone"   json:"userPhone"`   // 电话
+	ProductCode string      `orm:"product_code" json:"productCode"` // 产品线编码
+	ProductName string      `orm:"product_name" json:"productName"` // 产品线名称
+	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"` // 删除时间
+}

+ 141 - 0
opms_admin/app/service/base_product_auth.go

@@ -0,0 +1,141 @@
+package service
+
+import (
+	"context"
+	"dashoo.cn/micro/app/dao"
+	"dashoo.cn/micro/app/model"
+	"database/sql"
+	"fmt"
+	"github.com/gogf/gf/errors/gerror"
+	"github.com/gogf/gf/frame/g"
+	"github.com/gogf/gf/os/gtime"
+)
+
+type lineService struct {
+	*contextService
+
+	Dao *dao.BaseProductAuthDao
+}
+
+func NewLineService(ctx context.Context) (svc *lineService, err error) {
+	svc = new(lineService)
+	if svc.contextService, err = svc.Init(ctx); err != nil {
+		return nil, err
+	}
+	svc.Dao = dao.NewBaseProductAuthDao(svc.Tenant)
+	svc.Table = svc.Dao.Table
+	return svc, nil
+}
+
+// GetList 用户产品线列表
+func (s *lineService) GetList(req *model.BaseProductAuthSearchReq) (total int, lines []*model.BaseProductAuth, err error) {
+	lineModel := s.Dao.M
+	if req.UserId != 0 {
+		lineModel = lineModel.Where("user_id", req.UserId)
+	}
+	if req.UserName != "" {
+		lineModel = lineModel.Where("user_name", req.UserName)
+	}
+	if req.UserPost != "" {
+		lineModel = lineModel.Where("user_post", req.UserPost)
+	}
+	if req.UserPhone != "" {
+		lineModel = lineModel.Where("user_phone", req.UserPhone)
+	}
+	if req.ProductCode != "" {
+		lineModel = lineModel.Where("product_code", req.ProductCode)
+	}
+	if req.ProductName != "" {
+		lineModel = lineModel.Where("product_name", req.ProductName)
+	}
+
+	total, err = lineModel.Count()
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取总行数失败")
+	}
+
+	err = lineModel.Order("id ASC").Scan(&lines)
+	if err != nil {
+		g.Log().Error(err)
+		err = gerror.New("获取数据失败")
+	}
+	return
+}
+
+// Save 创建或更新数据
+func (s *lineService) Save(req *model.SaveBaseProductAuthReq) (err error) {
+	var newLines []*model.BaseProductAuth
+
+	// 标记删除旧数据
+	_, err = s.Dao.Where(fmt.Sprintf("user_id='%v'", req.UserId)).Update(fmt.Sprintf("deleted_time='%v'", gtime.Now()))
+	if err != nil {
+		return err
+	}
+
+	// 填入新数据
+	for _, line := range req.Lines {
+		data := &model.BaseProductAuth{
+			UserId:      req.UserId,
+			UserName:    req.UserName,
+			UserPhone:   req.UserPhone,
+			UserPost:    req.UserPost,
+			ProductCode: line.ProductCode,
+			ProductName: line.ProductName,
+			Remark:      line.Remark,
+		}
+		SetCreatedInfo(data, s.GetCxtUserId(), s.GetCxtUserName())
+		SetUpdatedInfo(data, s.GetCxtUserId(), s.GetCxtUserName())
+
+		newLines = append(newLines, data)
+	}
+	if len(newLines) > 0 {
+		_, err = s.Dao.Save(newLines)
+	}
+
+	return
+}
+
+func (s *lineService) GetProductLineUsers(req *model.SysUserSearchReq) (total int, lines []*model.BaseProductAuth, err error) {
+	userService, err := NewUserService(s.Ctx)
+	if err != nil {
+		return 0, nil, err
+	}
+
+	total, users, err := userService.GetUsersByDeptEx(req)
+	if err != nil {
+		return 0, nil, err
+	}
+
+	var userIds []int
+	for _, user := range users {
+		userIds = append(userIds, user.Id)
+	}
+
+	allLines, err := s.Dao.Where("user_id IN (?)", userIds).Order("user_id ASC, id ASC").FindAll()
+	if err != nil && err != sql.ErrNoRows {
+		return 0, nil, err
+	}
+	for _, user := range users {
+		var data model.BaseProductAuth
+		data.UserId = user.Id
+		data.UserName = user.NickName
+		data.UserPost = "" // TODO 暂时为空
+		data.UserPhone = user.Phone
+		for _, line := range allLines {
+			if user.Id == line.UserId {
+				if data.ProductCode == "" {
+					data.ProductCode = line.ProductCode
+					data.ProductName = line.ProductName
+				} else {
+					data.ProductCode += "," + line.ProductCode
+					data.ProductName += "," + line.ProductName
+				}
+			}
+		}
+
+		lines = append(lines, &data)
+	}
+
+	return
+}

+ 37 - 0
opms_admin/app/service/sys_user.go

@@ -129,6 +129,43 @@ func (s *UserService) GetUserByDept(deptId int) (userList []*model.SysUser, err
 	return userList, err
 }
 
+// GetUsersByDeptEx 获取部门及子部门下的用户
+func (s *UserService) GetUsersByDeptEx(req *model.SysUserSearchReq) (total int, userList []*model.SysUser, err error) {
+	depts, err := s.Dao.DB.Model("sys_dept").Fields("id").Wheref("find_in_set( %d , ancestors )", req.DeptId).FindAll()
+	if err != nil {
+		if err == sql.ErrNoRows {
+			return 0, nil, gerror.New("无部门数据")
+		}
+		return 0, nil, err
+	}
+	if len(depts) == 0 {
+		return 0, nil, gerror.New("无部门数据")
+	}
+	var depIds []int
+	for _, dep := range depts {
+		depIds = append(depIds, dep["id"].Int())
+	}
+
+	userModel := s.Dao.M
+	if req.Phone != "" {
+		userModel = userModel.Where("sys_user.phone", "%"+req.Phone+"%")
+	}
+	if req.KeyWords != "" {
+		keyWords := "%" + req.KeyWords + "%"
+		userModel = userModel.Where("sys_user.user_name like ? or  sys_user.nick_name like ?", keyWords, keyWords)
+	}
+	if len(depts) > 0 {
+		userModel = userModel.Where("dept_id IN (?)", depIds)
+	}
+	total, err = userModel.Count()
+	if err != nil {
+		return 0, nil, err
+	}
+
+	err = userModel.Page(req.GetPage()).Order("Id ASC").FieldsEx(s.Dao.Columns.Password, s.Dao.Columns.UserSalt).Scan(&userList)
+	return total, userList, err
+}
+
 // GetUserByRole 获取角色关联的用户
 func (s *UserService) GetUserByRole(roleId int) (userList []*model.SysUser, err error) {
 	count, err := dao.NewSysRoleDao(s.Tenant).Where(dao.SysRole.Columns.Id, roleId).Where(dao.SysRole.Columns.Status, "10").Count()

+ 1 - 0
opms_admin/main.go

@@ -25,6 +25,7 @@ func main() {
 	s.RegisterName("Group", new(handler.GroupHandler), "")
 	s.RegisterName("LoginLog", new(handler.LoginLogHandler), "")
 	s.RegisterName("Config", new(handler.ConfigHandler), "")
+	s.RegisterName("BaseProductAuth", new(handler.BaseProductAuthHandler), "")
 
 	// 注册文件处理Service对象
 	//dynamic.BeanFactory.BeanRegister(service.NewRoleService())

+ 1 - 1
opms_parent/app/service/dingtalk_log/dingtalk_log.go

@@ -35,7 +35,7 @@ func Create(ctx context.Context, logType, content string) {
 	entity.Content = content
 	service.SetCreatedInfo(&entity, srv.GetCxtUserId(), srv.GetCxtUserName())
 
-	_, err = srv.Dao.Save()
+	_, err = srv.Dao.Save(entity)
 	if err != nil {
 		glog.Error(err)
 		return