xyxie 11 сар өмнө
parent
commit
faf137fddf

+ 78 - 0
controllers/admin.go

@@ -1 +1,79 @@
 package controllers
+
+import (
+	"eta/eta_forum_admin/models"
+	"eta/eta_forum_admin/models/system"
+	"strconv"
+)
+
+type AdminController struct {
+	BaseAuthController
+}
+
+// GetBusinessAdmin
+// @Title 获取机构用户
+// @Description 获取机构用户
+// @Success 200 {object} models.ChartInfoDetailResp
+// @router /business/admin [get]
+func (this *AdminController) GetBusinessAdmin() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	// 查询所有机构
+	ob := new(system.EtaBusiness)
+	companyList, err := ob.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
+	if err != nil {
+		br.Msg = "获取机构信息失败"
+		br.ErrMsg = err.Error()
+		return
+	}
+	list := make([]*system.BusinessAdmin, 0)
+	//查询机构下的用户
+	admin := new(system.Admin)
+	adminList, err := admin.GetItemsByCondition("", make([]interface{}, 0), []string{}, "")
+	if err != nil {
+		br.Msg = "获取机构用户失败"
+		br.ErrMsg = err.Error()
+		return
+	}
+	companyMap := make(map[string][]*system.BusinessAdmin)
+	if len(adminList) > 0 {
+		for _, v := range adminList {
+			tmp := &system.BusinessAdmin{
+				AdminId:  strconv.Itoa(v.AdminId),
+				RealName: v.RealName,
+			}
+			companyMap[v.BusinessCode] = append(companyMap[v.BusinessCode], tmp)
+		}
+	}
+	if len(companyList) > 0 {
+
+		for _, v := range companyList {
+
+			tmp := &system.BusinessAdmin{
+				AdminId:  v.BusinessCode,
+				RealName: v.BusinessName,
+			}
+			l, ok := companyMap[v.BusinessCode]
+			if ok {
+				tmp.ChildrenList = l
+			}
+			list = append(list, tmp)
+		}
+	}
+	var resp system.BusinessAdminResp
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 36 - 50
controllers/chart_classify.go

@@ -119,55 +119,6 @@ func (this *ChartClassifyController) ChartClassifyListV2() {
 	br.Data = resp
 }
 
-// getChartClassifyListForMe 获取我创建的图表
-func getChartClassifyListForMe(adminInfo system.Admin, resp *models.ChartClassifyListResp) (errMsg string, err error) {
-	rootList, err := models.GetChartClassifyByParentId(0, utils.CHART_SOURCE_DEFAULT)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		errMsg = "获取失败"
-		return
-	}
-
-	classifyAll, err := models.GetChartClassifyAll(utils.CHART_SOURCE_DEFAULT)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		errMsg = "获取失败"
-		return
-	}
-
-	allChartInfo, err := models.GetChartInfoByAdminId([]int{utils.CHART_SOURCE_DEFAULT}, adminInfo.AdminId)
-	if err != nil && err.Error() != utils.ErrNoRow() {
-		errMsg = "获取失败"
-		return
-	}
-
-	chartInfoMap := make(map[int][]*models.ChartClassifyItems)
-	for _, v := range allChartInfo {
-		chartInfoMap[v.ChartClassifyId] = append(chartInfoMap[v.ChartClassifyId], v)
-	}
-	rootChildMap := make(map[int][]*models.ChartClassifyItems)
-	for _, v := range classifyAll {
-		rootChildMap[v.ParentId] = append(rootChildMap[v.ParentId], v)
-		if existItems, ok := chartInfoMap[v.ChartClassifyId]; ok {
-			v.Children = existItems
-		} else {
-			items := make([]*models.ChartClassifyItems, 0)
-			v.Children = items
-		}
-	}
-	nodeAll := make([]*models.ChartClassifyItems, 0)
-	for _, v := range rootList {
-		if existItems, ok := rootChildMap[v.ChartClassifyId]; ok {
-			v.Children = existItems
-		} else {
-			items := make([]*models.ChartClassifyItems, 0)
-			v.Children = items
-		}
-		nodeAll = append(nodeAll, v)
-	}
-	resp.AllNodes = nodeAll
-
-	return
-}
-
 // SimpleList
 // @Title 单层分类列表
 // @Description 单层分类列表
@@ -183,6 +134,23 @@ func (this *ChartClassifyController) SimpleList() {
 	// 如果是 子级分类,查询该子级分类的下一级分类和指标信息
 	// 增加标识判断是文件夹还是指标列表
 	reqParentId, _ := this.GetInt("ParentId")
+	sysUserIds := this.GetString("SysUserIds")
+	adminIdsSlice := make([]int, 0)
+	if sysUserIds != "" {
+		adminIds := strings.Split(sysUserIds, ",")
+		if len(adminIds) == 0 {
+			br.Msg = "请选择正确的创建人"
+			return
+		}
+		for _, adminId := range adminIds {
+			adminIdInt, e := strconv.Atoi(adminId)
+			if e != nil {
+				br.Msg = "请选择正确的创建人"
+				return
+			}
+			adminIdsSlice = append(adminIdsSlice, adminIdInt)
+		}
+	}
 	parentId := 0
 	nodeAll := make([]*models.ChartClassifyItems, 0)
 	// 处理未分类
@@ -202,14 +170,32 @@ func (this *ChartClassifyController) SimpleList() {
 		parentId = reqParentId
 	}
 	rootList := make([]*models.ChartClassifyItems, 0)
+	rootListTmp := make([]*models.ChartClassifyItems, 0)
 	var err error
 	if reqParentId == -1 {
-		rootList, err = models.GetChartClassifyByParentId(parentId, utils.CHART_SOURCE_DEFAULT)
+		rootListTmp, err = models.GetChartClassifyByParentId(parentId, utils.CHART_SOURCE_DEFAULT)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
+		if len(adminIdsSlice) > 0 {
+			// 判断是否存在某个创建人的图表,如果不存在某个创建人的图表则过滤
+			hasClassifyMap, e, _ := services.GetChartClassifyListByAdmins(adminIdsSlice)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取创建人图表失败,Err:" + e.Error()
+				return
+			}
+			for _, v := range rootListTmp {
+				if _, ok := hasClassifyMap[v.ChartClassifyId]; ok {
+					rootList = append(rootList, v)
+				}
+			}
+		} else {
+			rootList = rootListTmp
+		}
+
 	}
 
 	var sortList models.ChartClassifyItemList

+ 7 - 0
models/chart_classify.go

@@ -144,6 +144,13 @@ func GetChartClassifyAll(source int) (items []*ChartClassifyItems, err error) {
 	return
 }
 
+func GetChartClassify() (items []*ChartClassifyItems, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM chart_classify order by level desc, sort asc,chart_classify_id asc`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
 type ChartClassifyItems struct {
 	ChartClassifyId     int `description:"分类id"`
 	ChartInfoId         int `description:"指标id"`

+ 12 - 0
models/chart_info.go

@@ -1886,6 +1886,18 @@ func GetChartInfoTotalByAdminIdAndClassify(sourceList []int, adminIds []int, cla
 	return
 }
 
+// GetChartClassifyByAdminIdsAndLevel 根据创建者查询图表
+func GetChartClassifyByAdminIdsAndLevel(sourceList []int, adminIds []int) (items []*ChartClassifyItems, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT c.chart_info_id,c.chart_classify_id,c.chart_name AS chart_classify_name,
+             c.unique_code,c.sys_user_id,c.sys_user_real_name,c.date_type,c.start_date,c.end_date,c.chart_type,c.calendar,c.season_start_date,c.season_end_date,c.is_join_permission
+            FROM chart_info c
+            left join chart_classify a on c.chart_classify_id = a.chart_classify_id
+            where source in (` + utils.GetOrmInReplace(len(sourceList)) + `)  AND sys_user_id in (` + utils.GetOrmInReplace(len(adminIds)) + `) order by a.level asc`
+	_, err = o.Raw(sql, sourceList, adminIds).QueryRows(&items)
+	return
+}
+
 // GetChartInfoAdminList 根据条件获取图表数据了列表
 func GetChartInfoAdminList() (items []int, err error) {
 	o := orm.NewOrm()

+ 11 - 0
models/system/admin.go

@@ -64,6 +64,7 @@ type Admin struct {
 	EmployeeId                string    `description:"员工工号(钉钉/每刻报销)"`
 	TelAreaCode               string    `description:"手机区号"`
 	IsLdap                    int       `description:"是否为域用户:0-系统账户;1-域用户"`
+	BusinessCode              string    `description:"商家编码"`
 }
 
 // Update 更新用户基础信息
@@ -217,3 +218,13 @@ func GetUserUnexpiredSysSession(userName, expiredTime string) (item *SysSession,
 type AuthCodeLoginReq struct {
 	AuthCode string
 }
+
+type BusinessAdmin struct {
+	AdminId      string           `description:"系统用户id"`
+	RealName     string           `description:"用户真实名称"`
+	ChildrenList []*BusinessAdmin `description:"用户列表"`
+}
+
+type BusinessAdminResp struct {
+	List []*BusinessAdmin `description:"用户列表"`
+}

+ 244 - 0
models/system/eta_business.go

@@ -0,0 +1,244 @@
+package system
+
+import (
+	"eta/eta_forum_admin/utils"
+	"fmt"
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"strings"
+	"time"
+)
+
+const (
+	EtaBusinessSigningStatusFirst = iota + 1
+	EtaBusinessSigningStatusContinue
+	EtaBusinessSigningStatusTerminate
+	EtaBusinessSigningStatusWait
+)
+
+type EtaBusiness struct {
+	EtaBusinessId int       `orm:"column(eta_business_id);pk"`
+	BusinessName  string    `description:"商家名称"`
+	BusinessCode  string    `description:"商家编码"`
+	CodeEncrypt   string    `description:"商家编码加密"`
+	CreditCode    string    `description:"社会统一信用码"`
+	RegionType    string    `description:"所属区域:国内;海外"`
+	Province      string    `description:"省份"`
+	City          string    `description:"城市"`
+	Address       string    `description:"商家地址"`
+	CreateTime    time.Time `description:"创建时间"`
+	ModifyTime    time.Time `description:"更新时间"`
+}
+
+func (m *EtaBusiness) TableName() string {
+	return "eta_business"
+}
+
+func (m *EtaBusiness) PrimaryId() string {
+	return EtaBusinessColumns.EtaBusinessId
+}
+
+var EtaBusinessColumns = struct {
+	EtaBusinessId string
+	BusinessName  string
+	BusinessCode  string
+	CreditCode    string
+	RegionType    string
+	Province      string
+	City          string
+	Address       string
+	CreateTime    string
+	ModifyTime    string
+}{
+	EtaBusinessId: "eta_business_id",
+	BusinessName:  "business_name",
+	BusinessCode:  "business_code",
+	CreditCode:    "credit_code",
+	RegionType:    "region_type",
+	Province:      "province",
+	City:          "city",
+	Address:       "address",
+	CreateTime:    "create_time",
+	ModifyTime:    "modify_time",
+}
+
+func (m *EtaBusiness) Create() (err error) {
+	o := orm.NewOrm()
+	id, err := o.Insert(m)
+	if err != nil {
+		return
+	}
+	m.EtaBusinessId = int(id)
+	return
+}
+
+func (m *EtaBusiness) CreateMulti(items []*EtaBusiness) (err error) {
+	if len(items) == 0 {
+		return
+	}
+	o := orm.NewOrm()
+	_, err = o.InsertMulti(len(items), items)
+	return
+}
+
+func (m *EtaBusiness) Update(cols []string) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Update(m, cols...)
+	return
+}
+
+func (m *EtaBusiness) Del() (err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`DELETE FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	_, err = o.Raw(sql, m.EtaBusinessId).Exec()
+	return
+}
+
+func (m *EtaBusiness) GetItemById(id int) (item *EtaBusiness, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE %s = ? LIMIT 1`, m.TableName(), m.PrimaryId())
+	err = o.Raw(sql, id).QueryRow(&item)
+	return
+}
+
+func (m *EtaBusiness) GetItemByCondition(condition string, pars []interface{}) (item *EtaBusiness, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT * FROM %s WHERE 1=1 %s LIMIT 1`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&item)
+	return
+}
+
+func (m *EtaBusiness) GetCountByCondition(condition string, pars []interface{}) (count int, err error) {
+	o := orm.NewOrm()
+	sql := fmt.Sprintf(`SELECT COUNT(1) FROM %s WHERE 1=1 %s`, m.TableName(), condition)
+	err = o.Raw(sql, pars).QueryRow(&count)
+	return
+}
+
+func (m *EtaBusiness) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EtaBusiness, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}
+
+func (m *EtaBusiness) GetPageItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string, startSize, pageSize int) (items []*EtaBusiness, err error) {
+	o := orm.NewOrm()
+	fields := strings.Join(fieldArr, ",")
+	if len(fieldArr) == 0 {
+		fields = `*`
+	}
+	order := `ORDER BY create_time DESC`
+	if orderRule != "" {
+		order = ` ORDER BY ` + orderRule
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE 1=1 %s %s LIMIT ?,?`, fields, m.TableName(), condition, order)
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}
+
+// EtaBusinessAddReq 新增商家请求体
+type EtaBusinessAddReq struct {
+	BusinessName     string `description:"商家名称"`
+	CreditCode       string `description:"社会统一信用码"`
+	RegionType       string `description:"所属区域:国内;海外"`
+	Province         string `description:"省份"`
+	City             string `description:"城市"`
+	SellerId         int    `description:"销售ID"`
+	SellerName       string `description:"销售名称"`
+	Leader           string `description:"决策人"`
+	IndustryId       int    `description:"行业ID"`
+	IndustryName     string `description:"行业名称"`
+	CapitalScale     string `description:"资金规模"`
+	ResearchTeamSize string `description:"研究团队规模"`
+	UserMax          int    `description:"用户上限"`
+	SigningTime      string `description:"签约时间"`
+	ExpiredTime      string `description:"到期时间"`
+	IsCheck          bool   `description:"是否只做校验而不实际新增(业务操作上基础信息和签约时间分成两个步骤了)"`
+}
+
+// EtaBusinessEditReq 编辑商家请求体
+type EtaBusinessEditReq struct {
+	EtaBusinessId    int    `description:"商家ID"`
+	Province         string `description:"省份"`
+	City             string `description:"城市"`
+	Leader           string `description:"决策人"`
+	IndustryId       int    `description:"行业ID"`
+	IndustryName     string `description:"行业名称"`
+	CapitalScale     string `description:"资金规模"`
+	ResearchTeamSize string `description:"研究团队规模"`
+	UserMax          int    `description:"用户上限"`
+}
+
+// EtaBusinessSigningReq 商家签约请求体
+type EtaBusinessSigningReq struct {
+	EtaBusinessId int    `description:"商家ID"`
+	SigningTime   string `description:"当前合约的签约时间"`
+	ExpiredTime   string `description:"当前合约的到期时间"`
+}
+
+// EtaBusinessEnableReq 禁启用商家请求体
+type EtaBusinessEnableReq struct {
+	EtaBusinessId int `description:"商家ID"`
+}
+
+// EtaBusinessMoveSellerReq 移动商家销售请求体
+type EtaBusinessMoveSellerReq struct {
+	EtaBusinessId int    `description:"商家ID"`
+	SellerId      int    `description:"销售ID"`
+	SellerName    string `description:"销售名称"`
+}
+
+// CreateEtaBusinessCode 生成ETA商家编码
+func CreateEtaBusinessCode() (code string, err error) {
+	var num int
+	o := orm.NewOrm()
+	sql := `SELECT COUNT(1) AS num FROM eta_business WHERE create_time >= ? `
+	err = o.Raw(sql, time.Now().Format(utils.FormatDate)).QueryRow(&num)
+	if err != nil {
+		return
+	}
+	code = "E" + time.Now().Format("20060102") + fmt.Sprintf("%02d", num)
+	return
+}
+
+// EtaBusinessListResp 商家分页列表响应体
+type EtaBusinessListResp struct {
+	List   []*EtaBusinessItem `description:"商家列表数据"`
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+// EtaBusinessItem ETA商家信息
+type EtaBusinessItem struct {
+	EtaBusinessId    int
+	BusinessName     string `description:"商家名称"`
+	BusinessCode     string `description:"商家编码"`
+	CreditCode       string `description:"社会统一信用码"`
+	RegionType       string `description:"所属区域:国内;海外"`
+	Province         string `description:"省份"`
+	City             string `description:"城市"`
+	Address          string `description:"商家地址"`
+	SellerId         int    `description:"销售ID"`
+	SellerName       string `description:"销售名称"`
+	Leader           string `description:"决策人"`
+	IndustryId       int    `description:"行业ID"`
+	IndustryName     string `description:"行业名称"`
+	CapitalScale     string `description:"资金规模"`
+	ResearchTeamSize string `description:"研究团队规模"`
+	UserMax          int    `description:"用户上限"`
+	SigningStatus    int    `description:"签约状态:1-首次签约;2-续约中;3-已终止"`
+	Enable           int    `description:"状态:0-禁用;1-启用"`
+	ContractId       int    `description:"当前合约ID"`
+	SigningTime      string `description:"当前合约的签约时间"`
+	ExpiredTime      string `description:"当前合约的到期时间"`
+	CreateTime       string `description:"创建时间"`
+	ModifyTime       string `description:"更新时间"`
+}

+ 9 - 0
routers/commentsRouter.go

@@ -7,6 +7,15 @@ import (
 
 func init() {
 
+    beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:AdminController"] = append(beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:AdminController"],
+        beego.ControllerComments{
+            Method: "GetBusinessAdmin",
+            Router: `/business/admin`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:ChartClassifyController"] = append(beego.GlobalControllerRouter["eta/eta_forum_admin/controllers:ChartClassifyController"],
         beego.ControllerComments{
             Method: "DeleteChartClassifyCheck",

+ 5 - 0
routers/router.go

@@ -30,6 +30,11 @@ func init() {
 				&controllers.LoginController{},
 			),
 		),
+		web.NSNamespace("/admin",
+			web.NSInclude(
+				&controllers.AdminController{},
+			),
+		),
 	)
 	web.AddNamespace(ns)
 }

+ 48 - 0
services/chart_classify.go

@@ -737,3 +737,51 @@ func moveChartClassify(parentClassifyInfo, edbClassifyInfo, prevClassify, nextCl
 	}
 	return
 }
+
+// GetChartClassifyListByAdmins 获取某个创建者的图表分类
+func GetChartClassifyListByAdmins(adminIdsSlice []int) (hasClassifyMap map[int]bool, err error, errMsg string) {
+	classifyAll, err := models.GetChartClassify()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		errMsg = "获取失败"
+		return
+	}
+	if len(classifyAll) == 0 {
+		return
+	}
+
+	allChartInfo, err := models.GetChartClassifyByAdminIdsAndLevel([]int{utils.CHART_SOURCE_DEFAULT}, adminIdsSlice)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		errMsg = "获取失败"
+		return
+	}
+	if len(allChartInfo) == 0 {
+		return
+	}
+	hasClassifyMap = make(map[int]bool)
+	for _, v := range allChartInfo {
+		hasClassifyMap[v.ChartClassifyId] = true
+	}
+
+	// 遍历分类,如果存在则返回
+	for _, v := range classifyAll {
+		if _, ok := hasClassifyMap[v.ChartClassifyId]; ok {
+			hasClassifyMap[v.ParentId] = true
+		}
+	}
+
+	// 遍历分类,如果存在则返回
+	for _, v := range classifyAll {
+		if _, ok := hasClassifyMap[v.ChartClassifyId]; ok {
+			hasClassifyMap[v.ParentId] = true
+		}
+	}
+
+	// 遍历分类,如果存在则返回
+	for _, v := range classifyAll {
+		if _, ok := hasClassifyMap[v.ChartClassifyId]; ok {
+			hasClassifyMap[v.ParentId] = true
+		}
+	}
+
+	return
+}