Browse Source

pasture: 集团账号下发

Yi 1 year ago
parent
commit
0d46e86d2f
6 changed files with 105 additions and 2 deletions
  1. 19 0
      http/handle/group/feed_formula.go
  2. 4 2
      http/routers/app_api.go
  3. 8 0
      models/group_data.go
  4. 29 0
      models/user.go
  5. 41 0
      module/group.go
  6. 4 0
      service/group/group.go

+ 19 - 0
http/handle/group/feed_formula.go

@@ -83,3 +83,22 @@ func SprinkleStatistics(c *gin.Context) {
 		appG.Response(http.StatusOK, e.SUCCESS, res)
 	}
 }
+
+// DistributeAccount 账号下发
+func DistributeAccount(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req models.AccountDistributionRequest
+	if err := c.BindJSON(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+	if err := group.AccountDistributionService(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.ERROR_GET_S_FAIL, map[string]interface{}{
+			"error": err,
+		})
+	} else {
+		appG.Response(http.StatusOK, e.SUCCESS, map[string]bool{
+			"success": true,
+		})
+	}
+}

+ 4 - 2
http/routers/app_api.go

@@ -4,6 +4,7 @@ import (
 	"tmr-watch/comm"
 	"tmr-watch/conf/setting"
 	"tmr-watch/http/handle/api"
+	"tmr-watch/http/handle/group"
 	"tmr-watch/http/handle/sap"
 	"tmr-watch/http/handle/zc"
 	"tmr-watch/middleware/jwt"
@@ -25,8 +26,9 @@ func AppAPI(opts ...func(engine *gin.Engine)) func(s *gin.Engine) {
 
 		s.Static("/file", setting.CurrentPath+"/uploads/file")
 		s.Static("/uploads", setting.CurrentPath+"/uploads")
-		s.POST("/auth", api.Auth)           // 获取登录token
-		s.POST("/authlogin", api.AuthLogin) // 获取登录token
+		s.POST("/auth", api.Auth)                                      // 获取登录token
+		s.POST("/pasture/account/distribute", group.DistributeAccount) // 账号下发
+		s.POST("/authlogin", api.AuthLogin)                            // 获取登录token
 
 		s.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // API 注释
 

+ 8 - 0
models/group_data.go

@@ -109,3 +109,11 @@ type SprinkleStatisticsDataList struct {
 	ProcessTime string    `xorm:"processtime" json:"process_time"`
 	Times       int32     `xorm:"times" json:"times"`
 }
+
+type AccountDistributionRequest struct {
+	Account   string `json:"account"`
+	UserName  string `json:"user_name"`
+	Password  string `json:"password"`
+	Phone     string `json:"phone"`
+	PastureId int32  `json:"pasture_id"`
+}

+ 29 - 0
models/user.go

@@ -0,0 +1,29 @@
+package models
+
+import "time"
+
+type User struct {
+	Id          int64     `xorm:"id"`
+	PastureId   int64     `xorm:"pastureid"`
+	Isgroups    int32     `xorm:"isgroups"`
+	Username    string    `xorm:"username"`
+	Empname     string    `xorm:"empname"`
+	Password    string    `xorm:"password"`
+	Sort        int32     `xorm:"sort"`
+	Enable      int32     `xorm:"enable"`
+	Phone       string    `xorm:"phone"`
+	Createmp    string    `xorm:"createmp"`
+	Createdtime time.Time `xorm:"createdtime"`
+	Isdelete    int32     `xorm:"isdelete"`
+	Deletedtime time.Time `xorm:"deletedtime"`
+	Empid       int64     `xorm:"empid"`
+	CreatedOn   int64     `xorm:"created_On"`
+	DeletedOn   int64     `xorm:"deleted_On"`
+	Roleid      int64     `xorm:"roleid"`
+	Rolename    string    `xorm:"rolename"`
+	Imei        string    `xorm:"imei"`
+}
+
+func (u *User) TableName() string {
+	return "user"
+}

+ 41 - 0
module/group.go

@@ -1,10 +1,17 @@
 package module
 
 import (
+	"errors"
+	"time"
 	"tmr-watch/http/handle/restful"
 	"tmr-watch/models"
 )
 
+const (
+	IsOk = 1
+	IsNo = 2
+)
+
 // MixedFodderData 混料准确率和撒料准确率
 func MixedFodderData(req *models.AnalysisAccuracyRequest) ([]*models.MixedFodderDataList, error) {
 	res := make([]*models.MixedFodderDataList, 0)
@@ -131,3 +138,37 @@ func SprinkleStatistics(req *models.SprinkleStatisticsRequest) ([]*models.Sprink
 
 	return res, nil
 }
+
+func AccountDistribution(req *models.AccountDistributionRequest) error {
+	res := &models.User{}
+	_, err := restful.Engine.Select("pastureid,username,empname,password,phone").
+		Where("enable = ?", IsOk).And("isdelete = ?", IsNo).And("pastureid = ?", req.PastureId).
+		And("username = ?", req.Account).Get(res)
+	if err != nil {
+		return err
+	}
+	if res.Username == req.Account {
+		return errors.New("该账号已经存在")
+	}
+
+	newUser := &models.User{
+		PastureId:   int64(req.PastureId),
+		Isgroups:    IsOk,
+		Username:    req.Account,
+		Empname:     req.UserName,
+		Password:    req.Password,
+		Enable:      IsOk,
+		Phone:       req.Phone,
+		Createmp:    req.UserName,
+		Createdtime: time.Now(),
+		Isdelete:    IsNo,
+		Roleid:      0,
+		Rolename:    "",
+	}
+
+	if _, err = restful.Engine.Table(new(models.User).TableName()).Insert(newUser); err != nil {
+		return err
+	}
+
+	return nil
+}

+ 4 - 0
service/group/group.go

@@ -222,3 +222,7 @@ func SprinkleStatisticsService(req *models.SprinkleStatisticsRequest) ([]*models
 	}
 	return sprinkleDataList, nil
 }
+
+func AccountDistributionService(req *models.AccountDistributionRequest) error {
+	return module.AccountDistribution(req)
+}