Xingyu Xian 2 mesiacov pred
rodič
commit
ef84db5ea1

+ 7 - 6
db/job.go

@@ -37,16 +37,17 @@ func DeleteJob(ctx context.Context, job gorm_model.YounggeeJob) error {
 	return nil
 }
 
-// FindJobByEnterpriseId 按服务商ID查找岗位信息
-func FindJobByEnterpriseId(ctx context.Context, job gorm_model.YounggeeJob) ([]*gorm_model.YounggeeJob, error) {
+// FindJobBySupplierId 按服务商ID查找岗位信息
+func FindJobBySupplierId(ctx context.Context, supplierId int) ([]*gorm_model.YounggeeJob, int64, error) {
 	db := GetReadDB(ctx)
 	var Jobs []*gorm_model.YounggeeJob
-	whereCondition := gorm_model.YounggeeJob{SupplierId: job.SupplierId}
-	err := db.Model(gorm_model.YounggeeJob{}).Where(whereCondition).Find(&Jobs).Error
+	whereCondition := gorm_model.YounggeeJob{SupplierId: supplierId}
+	var total int64
+	err := db.Model(gorm_model.YounggeeJob{}).Where(whereCondition).Find(&Jobs).Count(&total).Error
 	if err != nil {
-		return nil, err
+		return nil, 0, err
 	}
-	return Jobs, nil
+	return Jobs, total, nil
 }
 
 // FindJobByJobId 按照岗位Id查找岗位信息

+ 16 - 0
db/sub_account.go

@@ -71,3 +71,19 @@ func FindSubAccountById(ctx context.Context, subAccountId int) (*gorm_model.Youn
 	}
 	return subAccount, nil
 }
+
+// FindSubAccountBySupplierId 根据服务商ID查找包含的所有子账号信息
+func FindSubAccountBySupplierId(ctx context.Context, supplierId int) ([]*gorm_model.YounggeeSubAccount, int64, error) {
+	db := GetReadDB(ctx)
+	var total int64
+	var subAccount []*gorm_model.YounggeeSubAccount
+	whereCondition := gorm_model.YounggeeSubAccount{SupplierId: supplierId, SubAccountType: 1}
+	err := db.Model(gorm_model.YounggeeSubAccount{}).Where(whereCondition).Find(&subAccount).Count(&total).Error
+	if err != nil {
+		return nil, 0, err
+	}
+	if total == 0 {
+		return nil, 0, err
+	}
+	return subAccount, total, nil
+}

+ 55 - 0
handler/delete_sub_account.go

@@ -0,0 +1,55 @@
+package handler
+
+import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+)
+
+func WrapDeleteSubAccountHandler(ctx *gin.Context) {
+	handler := newdeleteSubAccountHandler(ctx)
+	baseRun(handler)
+}
+
+func newdeleteSubAccountHandler(ctx *gin.Context) *DeleteSubAccountHandler {
+	return &DeleteSubAccountHandler{
+		req:  http_model.NewDeleteSubAccountRequest(),
+		resp: http_model.NewDeleteSubAccountResponse(),
+		ctx:  ctx,
+	}
+}
+
+type DeleteSubAccountHandler struct {
+	req  *http_model.DeleteSubAccountRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *DeleteSubAccountHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *DeleteSubAccountHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *DeleteSubAccountHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *DeleteSubAccountHandler) run() {
+	subAccountData := http_model.DeleteSubAccountRequest{}
+	subAccountData = *h.req
+	err := service.SubAccount.DeleteSubAccount(h.ctx, subAccountData)
+	if err != nil {
+		fmt.Println(err)
+		h.resp.Status = 40000
+		h.resp.Message = err.Error()
+		return
+	}
+	h.resp.Status = 20000
+	h.resp.Message = "ok"
+	return
+}
+
+func (h *DeleteSubAccountHandler) checkParam() error {
+	return nil
+}

+ 58 - 0
handler/find_all_job.go

@@ -0,0 +1,58 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+	"youngee_b_api/util"
+)
+
+func WrapFindAllJobHandler(ctx *gin.Context) {
+	handler := newFindAllJobHandler(ctx)
+	baseRun(handler)
+}
+
+func newFindAllJobHandler(ctx *gin.Context) *FindAllJobHandler {
+	return &FindAllJobHandler{
+		req:  http_model.NewFindAllJobRequest(),
+		resp: http_model.NewFindAllJobResponse(),
+		ctx:  ctx,
+	}
+}
+
+type FindAllJobHandler struct {
+	req  *http_model.FindAllJobRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *FindAllJobHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *FindAllJobHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *FindAllJobHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *FindAllJobHandler) run() {
+	data, err := service.Job.FindJobBySupplierId(h.ctx, *h.req)
+	if err != nil {
+		logrus.Errorf("[FindSubAccountByEnterpriseId] call SetSession err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, err.Error())
+		log.Info("FindSubAccountByEnterpriseId fail,req:%+v", h.req)
+		h.resp.Message = err.Error()
+		h.resp.Status = 40000
+		return
+	}
+	h.resp.Data = data
+	h.resp.Status = 20000
+	h.resp.Message = "ok"
+}
+
+func (h *FindAllJobHandler) checkParam() error {
+	return nil
+}

+ 58 - 0
handler/find_all_sub_account.go

@@ -0,0 +1,58 @@
+package handler
+
+import (
+	"github.com/gin-gonic/gin"
+	"github.com/sirupsen/logrus"
+	log "github.com/sirupsen/logrus"
+	"youngee_b_api/consts"
+	"youngee_b_api/model/http_model"
+	"youngee_b_api/service"
+	"youngee_b_api/util"
+)
+
+func WrapFindAllSubAccountHandler(ctx *gin.Context) {
+	handler := newFindAllSubAccountHandler(ctx)
+	baseRun(handler)
+}
+
+func newFindAllSubAccountHandler(ctx *gin.Context) *FindAllSubAccountHandler {
+	return &FindAllSubAccountHandler{
+		req:  http_model.NewFindAllSubAccountRequest(),
+		resp: http_model.NewFindAllSubAccountResponse(),
+		ctx:  ctx,
+	}
+}
+
+type FindAllSubAccountHandler struct {
+	req  *http_model.FindAllSubAccountRequest
+	resp *http_model.CommonResponse
+	ctx  *gin.Context
+}
+
+func (h *FindAllSubAccountHandler) getRequest() interface{} {
+	return h.req
+}
+func (h *FindAllSubAccountHandler) getContext() *gin.Context {
+	return h.ctx
+}
+func (h *FindAllSubAccountHandler) getResponse() interface{} {
+	return h.resp
+}
+func (h *FindAllSubAccountHandler) run() {
+	data, err := service.SubAccount.FindSubAccountBySupplierId(h.ctx, *h.req)
+	if err != nil {
+		logrus.Errorf("[FindSubAccountBySupplierId] call SetSession err:%+v\n", err)
+		util.HandlerPackErrorResp(h.resp, consts.ErrorInternal, err.Error())
+		log.Info("FindSubAccountBySupplierId fail,req:%+v", h.req)
+		h.resp.Message = err.Error()
+		h.resp.Status = 40000
+		return
+	}
+	h.resp.Data = data
+	h.resp.Status = 20000
+	h.resp.Message = "ok"
+}
+
+func (h *FindAllSubAccountHandler) checkParam() error {
+	return nil
+}

+ 14 - 0
model/http_model/delete_sub_account.go

@@ -0,0 +1,14 @@
+package http_model
+
+type DeleteSubAccountRequest struct {
+	SubAccountId int `json:"sub_account_id"` // 子账号ID
+}
+
+func NewDeleteSubAccountRequest() *DeleteSubAccountRequest {
+	return new(DeleteSubAccountRequest)
+}
+
+func NewDeleteSubAccountResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	return resp
+}

+ 25 - 0
model/http_model/find_all_job.go

@@ -0,0 +1,25 @@
+package http_model
+
+import "youngee_b_api/model/gorm_model"
+
+type FindAllJobRequest struct {
+	SupplierId int `json:"supplier_id"` // 子账号属于的服务商id
+}
+
+type FindAllJobInfo struct {
+}
+
+type FindAllJobData struct {
+	JobInfo []*gorm_model.YounggeeJob `json:"job_info"` // 岗位信息
+	Total   int64                     `json:"total"`    // 总数
+}
+
+func NewFindAllJobRequest() *FindAllJobRequest {
+	return new(FindAllJobRequest)
+}
+
+func NewFindAllJobResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(FindAllJobData)
+	return resp
+}

+ 31 - 0
model/http_model/find_all_sub_account.go

@@ -0,0 +1,31 @@
+package http_model
+
+type FindAllSubAccountRequest struct {
+	SupplierId int `json:"supplier_id"` // 子账号属于的服务商id
+}
+
+type FindAllSubAccountInfo struct {
+	SubAccountId   int    `json:"sub_account_id"`   // 子账号ID
+	PhoneNumber    string `json:"phone_number"`     // 手机号
+	SubAccountName string `json:"sub_account_name"` // 子账号名称
+	JobId          int    `json:"job_id"`           // 岗位ID
+	JobName        string `json:"job_name"`         // 岗位名称
+	SupplierId     int    `json:"supplier_id"`      // 所属服务商ID
+	AccountStatus  int    `json:"account_status"`   // 账号状态,1为正常,2为停用
+	UserId         int    `json:"user_id"`          // 用户表中ID
+}
+
+type FindAllSubAccountData struct {
+	SubAccountInfo []*FindAllSubAccountInfo `json:"sub_account_info"` // 子账号信息列表
+	Total          int64                    `json:"total"`            // 总数
+}
+
+func NewFindAllSubAccountRequest() *FindAllSubAccountRequest {
+	return new(FindAllSubAccountRequest)
+}
+
+func NewFindAllSubAccountResponse() *CommonResponse {
+	resp := new(CommonResponse)
+	resp.Data = new(FindAllSubAccountData)
+	return resp
+}

+ 10 - 7
route/init.go

@@ -14,13 +14,16 @@ func InitRoute(r *gin.Engine) {
 	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) // nothing
 	a := r.Group("/youngee")
 	{
-		a.POST("/register", handler.WrapRegisterHandler)                 // 服务商主账号注册
-		a.POST("/addNewSubAccount", handler.WrapAddNewSubAccountHandler) // 服务商子账号注册
-		a.POST("/addNewJob", handler.WrapaddNewJobHandler)               // 服务商新增岗位
-		a.POST("/updateJob", handler.WrapupdateJobHandler)               // 服务商修改岗位
-		a.POST("/deleteJob", handler.WrapdeleteJobHandler)               // 服务商删除岗位
-		a.POST("/sendCode", handler.WrapSendCodeHandler)                 // 发送登录验证码
-		a.POST("/login", handler.WrapCodeLoginHandler)                   // 服务商登录
+		a.POST("/register", handler.WrapRegisterHandler)                   // 服务商主账号注册
+		a.POST("/addNewSubAccount", handler.WrapAddNewSubAccountHandler)   // 服务商子账号注册
+		a.POST("/findAllSubAccount", handler.WrapFindAllSubAccountHandler) // 查找全部所属子账号
+		a.POST("/deleteSubAccount", handler.WrapDeleteSubAccountHandler)   // 删除子账号
+		a.POST("/findAllJob", handler.WrapFindAllJobHandler)               // 查找服务商全部所属岗位
+		a.POST("/addNewJob", handler.WrapaddNewJobHandler)                 // 服务商新增岗位
+		a.POST("/updateJob", handler.WrapupdateJobHandler)                 // 服务商修改岗位
+		a.POST("/deleteJob", handler.WrapdeleteJobHandler)                 // 服务商删除岗位
+		a.POST("/sendCode", handler.WrapSendCodeHandler)                   // 发送登录验证码
+		a.POST("/login", handler.WrapCodeLoginHandler)                     // 服务商登录
 		a.GET("/test/ping", func(c *gin.Context) {
 			resp := http_model.CommonResponse{
 				Status:  0,

+ 19 - 0
service/job.go

@@ -59,3 +59,22 @@ func (*job) DeleteJob(ctx context.Context, request http_model.DeleteJobRequest)
 	}
 	return nil
 }
+
+// FindJobBySupplierId 根据商家ID查找岗位
+func (*job) FindJobBySupplierId(ctx context.Context, request http_model.FindAllJobRequest) (*http_model.FindAllJobData, error) {
+	var jobNameData *http_model.FindAllJobData
+	jobNameData = &http_model.FindAllJobData{}
+	jobInfo, total, jobErr := db.FindJobBySupplierId(ctx, request.SupplierId)
+	if jobErr != nil {
+		return nil, jobErr
+	}
+	if jobInfo != nil {
+		for _, jobData := range jobInfo {
+			jobNameData.JobInfo = append(jobNameData.JobInfo, jobData)
+		}
+		jobNameData.Total = total
+	} else {
+		jobNameData.Total = 0
+	}
+	return jobNameData, nil
+}

+ 40 - 2
service/sub_account.go

@@ -62,9 +62,9 @@ func (*subaccount) UpdateSubAccount(ctx context.Context, request http_model.Upda
 }
 
 // DeleteSubAccount 删除子账号
-func (*subaccount) DeleteSubAccount(ctx context.Context, request http_model.DeleteJobRequest) error {
+func (*subaccount) DeleteSubAccount(ctx context.Context, request http_model.DeleteSubAccountRequest) error {
 	var newSubAccount = gorm_model.YounggeeSubAccount{
-		JobId: request.JobId,
+		SubAccountId: request.SubAccountId,
 	}
 	err := db.DeleteSubAccount(ctx, newSubAccount)
 	if err != nil {
@@ -72,3 +72,41 @@ func (*subaccount) DeleteSubAccount(ctx context.Context, request http_model.Dele
 	}
 	return nil
 }
+
+// FindSubAccountBySupplierId 根据服务商ID查找包含的所有子账号信息
+func (*subaccount) FindSubAccountBySupplierId(ctx context.Context, request http_model.FindAllSubAccountRequest) (*http_model.FindAllSubAccountData, error) {
+	var subAccountResp *http_model.FindAllSubAccountData
+	subAccountResp = &http_model.FindAllSubAccountData{}
+
+	// 1. 取出子账号基本信息
+	newSubAccount, total, subaccountErr := db.FindSubAccountBySupplierId(ctx, request.SupplierId)
+	if subaccountErr != nil {
+		return nil, subaccountErr
+	}
+	if newSubAccount != nil {
+		for _, s := range newSubAccount {
+			var subAccountInfo *http_model.FindAllSubAccountInfo
+			subAccountInfo = &http_model.FindAllSubAccountInfo{}
+			// fmt.Println("s:", s.SubAccountId)
+			subAccountInfo.SubAccountId = s.SubAccountId
+			subAccountInfo.SubAccountName = s.SubAccountName
+			subAccountInfo.JobId = s.JobId
+			subAccountInfo.UserId = s.UserId
+			subAccountInfo.PhoneNumber = s.PhoneNumber
+			subAccountInfo.SupplierId = s.SupplierId
+			subAccountInfo.AccountStatus = s.AccountStatus
+
+			// 2. 岗位信息
+			jobInfo, jobErr := db.FindJobByJobId(ctx, s.JobId)
+			if jobErr != nil {
+				return nil, jobErr
+			}
+			if jobInfo != nil {
+				subAccountInfo.JobName = jobInfo.JobName
+			}
+			subAccountResp.SubAccountInfo = append(subAccountResp.SubAccountInfo, subAccountInfo)
+		}
+	}
+	subAccountResp.Total = total
+	return subAccountResp, nil
+}