作者 tangxvhui

合伙人管理模块初步完成

... ... @@ -4,6 +4,7 @@ import (
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type CreatePartnerInfoCommand struct {
... ... @@ -22,9 +23,17 @@ type CreatePartnerInfoCommand struct {
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []*domain.Salesman `json:"salesman,omitempty"`
Salesman []domain.Salesman `json:"salesman,omitempty"`
}
func (command CreatePartnerInfoCommand) ValidateCommand() error {
if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
}
if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_3) {
return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
}
return nil
}
... ...
package command
import (
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type StatusPartnerInfoCommand struct {
// 合伙人ID
Id int64 `json:"id"`
Status int `json:"status"`
}
func (c *StatusPartnerInfoCommand) ValidateCommand() error {
func (command *StatusPartnerInfoCommand) ValidateCommand() error {
if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
}
return nil
}
... ...
package command
import (
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type UpdatePartnerInfoCommand struct {
... ... @@ -14,9 +17,19 @@ type UpdatePartnerInfoCommand struct {
// 区域
RegionInfo *domain.RegionInfo `json:"regionInfo"`
//关联业务员
Salesman []*domain.Salesman `json:"salesman,omitempty"`
Salesman []domain.Salesman `json:"salesman,omitempty"`
//合作时间
CooperateTime time.Time `json:"cooperateTime"`
}
func (c *UpdatePartnerInfoCommand) ValidateCommand() error {
func (command *UpdatePartnerInfoCommand) ValidateCommand() error {
if !(command.Status == domain.PARTNER_STATUS_NO || command.Status == domain.PARTNER_STATUS_YES) {
return lib.ThrowError(lib.ARG_ERROR, "合伙人状态错误")
}
if !(command.PartnerCategory == domain.PARTNER_CATEGORY_1 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_2 ||
command.PartnerCategory == domain.PARTNER_CATEGORY_3) {
return lib.ThrowError(lib.ARG_ERROR, "合伙类别错误")
}
return nil
}
... ...
... ... @@ -3,7 +3,9 @@ package query
type ListPartnerInfoQuery struct {
// 合伙人类别
Partnertype int `json:"partnerType"`
//所属区域
RegionInfo string `json:"regionInfo"`
// 合伙人姓名
PartnerName string `json:"partnerName"`
// 查询偏离量
Offset int `json:"offset"`
... ...
... ... @@ -76,7 +76,7 @@ func (PartnerInfoService *PartnerInfoService) CreatePartnerInfo(command *command
}
// GetPartnerInfo 返回合伙人
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command *query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
func (PartnerInfoService *PartnerInfoService) GetPartnerInfo(command query.GetPartnerInfoQuery) (data *domain.PartnerInfo, err error) {
var (
transactionContext, _ = factory.CreateTransactionContext(nil)
)
... ...
... ... @@ -2,6 +2,19 @@ package domain
import "time"
// 状态(1:启用或者0:禁用)
const (
PARTNER_STATUS_NO int = 0
PARTNER_STATUS_YES int = 1
)
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
const (
PARTNER_CATEGORY_1 int = 1
PARTNER_CATEGORY_2 int = 2
PARTNER_CATEGORY_3 int = 3
)
type PartnerInfo struct {
// 合伙人ID
Id int64 `json:"id"`
... ... @@ -15,7 +28,6 @@ type PartnerInfo struct {
Status int `json:"status"`
// 合伙类别 (1.研发合伙人 2.业务合伙人 3.事业)
PartnerCategory int `json:"partnerCategory"`
//创建时间
CreateAt time.Time `json:"createAt"`
//更新时间
... ... @@ -25,7 +37,7 @@ type PartnerInfo struct {
//关联业务员//所属区域信息
RegionInfo *RegionInfo `json:"regionInfo"`
Salesman []*Salesman `json:"salesman"`
Salesman []Salesman `json:"salesman"`
}
type PartnerFindOneQuery struct {
... ...
... ... @@ -31,7 +31,7 @@ type PartnerInfo struct {
//合作时间
CooperateTime time.Time
//关联业务员
Salesman []*domain.Salesman
Salesman []domain.Salesman
}
var _ pg.BeforeUpdateHook = (*PartnerInfo)(nil)
... ...
... ... @@ -114,8 +114,6 @@ func (controller *BaseController) GetHeaderToken() string {
}
func (controller *BaseController) ValidJWTToken() bool {
controller.setUserId(2)
return true
headerToken := controller.GetHeaderToken()
mytoken := new(lib.MyToken)
err := mytoken.ValidJWTToken(headerToken)
... ...
package controllers
import (
"crypto/sha1"
"errors"
"fmt"
"strconv"
"time"
"github.com/astaxie/beego/logs"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
partnerQuery "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/query"
partnerInfoCmd "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/command"
partnerInfoService "gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/partnerInfo/service"
... ... @@ -47,57 +54,237 @@ func (c *PartnerInfoController) CreatePartnerInfo() {
c.ResponseError(errors.New("json数据解析失败"))
return
}
cmd := partnerInfoCmd.CreatePartnerInfoCommand{}
defaultPwd := fmt.Sprintf("%x", sha1.Sum([]byte("123456")))
state, _ := strconv.Atoi(param.State)
cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local)
if err != nil {
e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
c.ResponseError(e)
return
}
cmd := partnerInfoCmd.CreatePartnerInfoCommand{
PartnerName: param.PartnerName,
Account: param.Account,
Password: defaultPwd,
Status: state,
PartnerCategory: param.PartnerType,
CooperateTime: cooperateTime,
RegionInfo: &domain.RegionInfo{
RegionName: param.Area,
},
Salesman: []domain.Salesman{
domain.Salesman{
Name: param.SalesmanName,
Telephone: param.Phone,
},
},
}
serve := partnerInfoService.NewPartnerInfoService(nil)
serve.CreatePartnerInfo(&cmd)
_, err = serve.CreatePartnerInfo(&cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
//UpdatePartnerInfo 更新合伙人
func (c *PartnerInfoController) UpdatePartnerInfo() {
// var (
// service = service.NewPartnerInfoService(nil)
// command = &command.UpdatePartnerInfoCommand{}
// )
// controller.JsonUnmarshal(command)
// id, _ := controller.GetInt(":id")
// command.Id = id
// controller.HandlerResponse(service.UpdatePartnerInfo(command))
//用与适配前端定义的数据结构
type Parameter struct {
ID int64 `json:"id"`
PartnerType int `json:"partnerType"`
Area string `json:"area"`
State string `json:"state"`
CooperationTime string `json:"cooperationTime"`
SalesmanName string `json:"salesmanName"`
Phone string `json:"phone"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
state, _ := strconv.Atoi(param.State)
cooperateTime, err := time.ParseInLocation("2006-01-02", param.CooperationTime, time.Local)
if err != nil {
e := lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
c.ResponseError(e)
return
}
cmd := partnerInfoCmd.UpdatePartnerInfoCommand{
Status: state,
PartnerCategory: param.PartnerType,
CooperateTime: cooperateTime,
RegionInfo: &domain.RegionInfo{
RegionName: param.Area,
},
Salesman: []domain.Salesman{
domain.Salesman{
Name: param.SalesmanName,
Telephone: param.Phone,
},
},
}
serve := partnerInfoService.NewPartnerInfoService(nil)
err = serve.UpdatePartnerInfo(&cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
//GetPartnerInfo 获取合伙人
func (c *PartnerInfoController) GetPartnerInfo() {
// var (
// service = service.NewPartnerInfoService(nil)
// command = &query.GetPartnerInfoQuery{}
// )
// uid, _ := controller.GetInt(":id")
// command.Id = uid
// controller.HandlerResponse(service.GetPartnerInfo(command))
//用与适配前端定义的数据结构
type Parameter struct {
Id int64 `json:"id"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
partnerInfo, err := newPartnerService.GetPartnerInfo(partnerQuery.GetPartnerInfoQuery{
Id: param.Id,
})
if err != nil {
c.ResponseError(err)
return
}
//数据适配
rspResult := map[string]interface{}{
"account": partnerInfo.Account,
"partnerName": partnerInfo.PartnerName,
"partnertype": partnerInfo.PartnerCategory,
"area": partnerInfo.RegionInfo.RegionName,
"salesmanName": "",
"phone": "",
"createTime": partnerInfo.CreateAt.Format("2006-01-02 15:04:05"),
"cooperationTime": partnerInfo.CooperateTime.Format("2006-01-02"),
"state": fmt.Sprint(partnerInfo.Status),
"id": partnerInfo.Id,
}
if len(partnerInfo.Salesman) > 0 {
rspResult["salesmanName"] = partnerInfo.Salesman[0].Name
rspResult["phone"] = partnerInfo.Salesman[0].Telephone
}
c.ResponseData(rspResult)
return
}
//GetPartnerInfo 移除合伙人
func (controller *PartnerInfoController) RemovePartnerInfo() {
// var (
// service = service.NewPartnerInfoService(nil)
// command = &command.RemovePartnerInfoCommand{}
// )
// uid, _ := controller.GetInt(":id")
// command.Id = uid
// controller.HandlerResponse(service.RemovePartnerInfo(command))
func (c *PartnerInfoController) PartnerInfoSetState() {
//用与适配前端定义的数据结构
type Parameter struct {
Id int64 `json:"id"`
status string `json:"status"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
cmd := partnerInfoCmd.StatusPartnerInfoCommand{
Id: param.Id,
}
if param.status == "1" {
//禁用操作
cmd.Status = domain.PARTNER_STATUS_NO
} else if param.status == "2" {
//启用操作
cmd.Status = domain.PARTNER_STATUS_YES
} else {
//错误
c.ResponseError(lib.ThrowError(lib.ARG_ERROR, "状态错误"))
return
}
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
err = newPartnerService.UpdateStatus(cmd)
if err != nil {
c.ResponseError(err)
return
}
c.ResponseData(nil)
return
}
//ListPartnerInfo 合伙人列表
func (controller *PartnerInfoController) ListPartnerInfo() {
// var (
// service = service.NewPartnerInfoService(nil)
// command = &query.ListPartnerInfoQuery{}
// )
// command.PartnerCategory, _ = controller.GetInt("partnerCategory")
// command.Status, _ = controller.GetInt("status")
// command.SortByCreateTime = controller.GetString("sortByCreateTime")
// command.SortByUpdateTime = controller.GetString("sortByUpdateTime")
// command.Offset, command.Limit = controller.GetLimitInfo()
// controller.HandlerResponse(service.ListPartnerInfo(command))
func (c *PartnerInfoController) ListPartnerInfo() {
type Parameter struct {
Partnertype string `json:"partnerType"`
Area string `json:"area"`
PartnerName string `json:"partnerName"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
var (
param Parameter
err error
)
if err = c.BindJsonData(&param); err != nil {
logs.Error(err)
c.ResponseError(errors.New("json数据解析失败"))
return
}
partnertype, _ := strconv.Atoi(param.Partnertype)
if param.PageNumber == 0 {
param.PageNumber = 20
}
query := partnerQuery.ListPartnerInfoQuery{
Partnertype: partnertype,
PartnerName: param.PartnerName,
RegionInfo: param.Area,
Limit: param.PageNumber,
}
if param.PageSize == 0 {
query.Offset = 0
} else {
query.Offset = (param.PageNumber - 1) * param.PageSize
}
newPartnerService := partnerInfoService.NewPartnerInfoService(nil)
count, partners, err := newPartnerService.ListPartnerInfo(&query)
if err != nil {
c.ResponseError(err)
return
}
resp := []map[string]interface{}{}
for i := range partners {
m := map[string]interface{}{
"id": partners[i].Id,
"account": partners[i].Account,
"partnerName": partners[i].PartnerName,
"area": partners[i].RegionInfo.RegionName,
"createTime": partners[i].CreateAt.Format("2006-01-02 15:04:05"),
"cooperationTime": partners[i].CooperateTime.Format("2006-01-02"),
"state": fmt.Sprint(partners[i].Status),
"salesmanName": "",
"phone": "",
}
if len(partners[i].Salesman) > 0 {
m["salesmanName"] = partners[i].Salesman[0].Name
m["phone"] = partners[i].Salesman[0].Telephone
}
resp = append(resp, m)
}
c.ResponsePageList(resp, count, param.PageNumber)
return
}
... ...
... ... @@ -20,6 +20,13 @@ func init() {
beego.NSRouter("/forbidden", &controllers.AdminUserController{}, "POST:ForbiddenAdminUser"),
beego.NSRouter("/permission", &controllers.AdminUserController{}, "POST:BeforeEditAdminUser"),
),
beego.NSNamespace("/partners",
beego.NSRouter("/list", &controllers.PartnerInfoController{}, "POST:ListPartnerInfo"),
beego.NSRouter("/add", &controllers.PartnerInfoController{}, "POST:CreatePartnerInfo"),
beego.NSRouter("/edit", &controllers.PartnerInfoController{}, "POST:UpdatePartnerInfo"),
beego.NSRouter("/detail", &controllers.PartnerInfoController{}, "POST:GetPartnerInfo"),
beego.NSRouter("/set-status", &controllers.PartnerInfoController{}, "POST:PartnerInfoSetState"),
),
)
beego.AddNamespace(adminRouter)
}
... ...