作者 陈志颖

feat:添加用户网关服务

@@ -10,7 +10,7 @@ import ( @@ -10,7 +10,7 @@ import (
10 10
11 type UpdateCooperationProjectCommand struct { 11 type UpdateCooperationProjectCommand struct {
12 // 共创项目ID 12 // 共创项目ID
13 - CooperationProjectId int64 `cname:"共创项目ID" json:"cooperationProjectId,string" valid:"Required"` 13 + CooperationProjectId string `cname:"共创项目ID" json:"cooperationProjectId" valid:"Required"`
14 // 共创项目名称 14 // 共创项目名称
15 CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName" valid:"Required"` 15 CooperationProjectName string `cname:"共创项目名称" json:"cooperationProjectName" valid:"Required"`
16 // 承接对象,1员工,2共创用户,3公开,可以多选 16 // 承接对象,1员工,2共创用户,3公开,可以多选
@@ -4,10 +4,14 @@ import "os" @@ -4,10 +4,14 @@ import "os"
4 4
5 const SERVICE_NAME = "allied-creation-cooperation" 5 const SERVICE_NAME = "allied-creation-cooperation"
6 6
  7 +// 日志相关设置
7 var LOG_LEVEL = "debug" 8 var LOG_LEVEL = "debug"
8 var LOG_FILE = "app.log" 9 var LOG_FILE = "app.log"
9 var LOG_PREFIX = "[allied-creation-cooperation]" 10 var LOG_PREFIX = "[allied-creation-cooperation]"
10 11
  12 +// 用户信息模块地址
  13 +var USER_MODULE_HOST = ""
  14 +
11 func init() { 15 func init() {
12 if os.Getenv("LOG_LEVEL") != "" { 16 if os.Getenv("LOG_LEVEL") != "" {
13 LOG_LEVEL = os.Getenv("LOG_LEVEL") 17 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -18,4 +22,7 @@ func init() { @@ -18,4 +22,7 @@ func init() {
18 if os.Getenv("LOG_PREFIX") != "" { 22 if os.Getenv("LOG_PREFIX") != "" {
19 LOG_PREFIX = os.Getenv("LOG_PREFIX") 23 LOG_PREFIX = os.Getenv("LOG_PREFIX")
20 } 24 }
  25 + if os.Getenv("USER_MODULE_HOST") != "" {
  26 + USER_MODULE_HOST = os.Getenv("USER_MODULE_HOST")
  27 + }
21 } 28 }
  1 +package service_gateway
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/constant"
  5 + "strings"
  6 + "time"
  7 +)
  8 +
  9 +type HttplibUserServiceGateway struct {
  10 + httplibBaseServiceGateway
  11 +}
  12 +
  13 +func (serviceGateway *HttplibUserServiceGateway) GetUser(uid int64) (map[string]interface{}, error) {
  14 + url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
  15 + request := serviceGateway.createRequest(url, "post")
  16 + options := make(map[string]interface{})
  17 + options["uid"] = uid
  18 + request.JSONBody(options)
  19 + response := make(map[string]interface{})
  20 + request.ToJSON(&response)
  21 + data, err := serviceGateway.responseHandle(response)
  22 + return data, err
  23 +}
  24 +
  25 +func (serviceGateway *HttplibUserServiceGateway) GetCompany(companyId int64) (map[string]interface{}, error) {
  26 + url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
  27 + request := serviceGateway.createRequest(url, "post")
  28 + options := make(map[string]interface{})
  29 + options["companyId"] = companyId
  30 + request.JSONBody(options)
  31 + response := make(map[string]interface{})
  32 + request.ToJSON(&response)
  33 + data, err := serviceGateway.responseHandle(response)
  34 + return data, err
  35 +}
  36 +
  37 +func (serviceGateway *HttplibUserServiceGateway) GetOrganization(organizationId int64) (map[string]interface{}, error) {
  38 + url := strings.Join([]string{serviceGateway.baseURL, ""}, "/")
  39 + request := serviceGateway.createRequest(url, "post")
  40 + options := make(map[string]interface{})
  41 + options["orgId"] = organizationId
  42 + request.JSONBody(options)
  43 + response := make(map[string]interface{})
  44 + request.ToJSON(&response)
  45 + data, err := serviceGateway.responseHandle(response)
  46 + return data, err
  47 +}
  48 +
  49 +func NewHttplibUserServiceGateway() *HttplibUserServiceGateway {
  50 + return &HttplibUserServiceGateway{
  51 + httplibBaseServiceGateway: httplibBaseServiceGateway{
  52 + baseURL: constant.USER_MODULE_HOST,
  53 + connectTimeout: 100 * time.Second,
  54 + readWriteTimeout: 30 * time.Second,
  55 + },
  56 + }
  57 +}
1 package service_gateway 1 package service_gateway
  2 +
  3 +type UserServiceGateway interface {
  4 + GetUser(uid int64) (map[string]interface{}, error)
  5 + GetCompany(companyId int64) (map[string]interface{}, error)
  6 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/web/beego"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/command"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/query"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application/cooperationProject/service"
  8 +)
  9 +
  10 +type CooperationProjectController struct {
  11 + beego.BaseController
  12 +}
  13 +
  14 +func (controller *CooperationProjectController) ReleaseCooperationProject() {
  15 + cooperationProjectService := service.NewCooperationProjectService(nil)
  16 + releaseCooperationProjectCommand := &command.ReleaseCooperationProjectCommand{}
  17 + controller.Unmarshal(releaseCooperationProjectCommand)
  18 + data, err := cooperationProjectService.ReleaseCooperationProject(releaseCooperationProjectCommand)
  19 + controller.Response(data, err)
  20 +}
  21 +
  22 +func (controller *CooperationProjectController) CreateCooperationProject() {
  23 + cooperationProjectService := service.NewCooperationProjectService(nil)
  24 + createCooperationProjectCommand := &command.CreateCooperationProjectCommand{}
  25 + controller.Unmarshal(createCooperationProjectCommand)
  26 + data, err := cooperationProjectService.CreateCooperationProject(createCooperationProjectCommand)
  27 + controller.Response(data, err)
  28 +}
  29 +
  30 +func (controller *CooperationProjectController) UpdateCooperationProject() {
  31 + cooperationProjectService := service.NewCooperationProjectService(nil)
  32 + updateCooperationProjectCommand := &command.UpdateCooperationProjectCommand{}
  33 + controller.Unmarshal(updateCooperationProjectCommand)
  34 + cooperationProjectId := controller.GetString(":cooperationProjectId")
  35 + updateCooperationProjectCommand.CooperationProjectId = cooperationProjectId
  36 + data, err := cooperationProjectService.UpdateCooperationProject(updateCooperationProjectCommand)
  37 + controller.Response(data, err)
  38 +}
  39 +
  40 +func (controller *CooperationProjectController) GetCooperationProject() {
  41 + cooperationProjectService := service.NewCooperationProjectService(nil)
  42 + getCooperationProjectQuery := &query.GetCooperationProjectQuery{}
  43 + cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId")
  44 + getCooperationProjectQuery.CooperationProjectId = cooperationProjectId
  45 + data, err := cooperationProjectService.GetCooperationProject(getCooperationProjectQuery)
  46 + controller.Response(data, err)
  47 +}
  48 +
  49 +func (controller *CooperationProjectController) RemoveCooperationProject() {
  50 + cooperationProjectService := service.NewCooperationProjectService(nil)
  51 + removeCooperationProjectCommand := &command.RemoveCooperationProjectCommand{}
  52 + controller.Unmarshal(removeCooperationProjectCommand)
  53 + cooperationProjectId, _ := controller.GetInt64(":cooperationProjectId")
  54 + removeCooperationProjectCommand.CooperationProjectId = cooperationProjectId
  55 + data, err := cooperationProjectService.RemoveCooperationProject(removeCooperationProjectCommand)
  56 + controller.Response(data, err)
  57 +}
  58 +
  59 +func (controller *CooperationProjectController) SearchCooperationProject() {
  60 + cooperationProjectService := service.NewCooperationProjectService(nil)
  61 + searchCooperationProjectQuery := &query.SearchCooperationProjectQuery{}
  62 + data, err := cooperationProjectService.SearchCooperationProject(searchCooperationProjectQuery)
  63 + controller.Response(data, err)
  64 +}
  65 +
  66 +func (controller *CooperationProjectController) CheckUndertaker() {
  67 + cooperationProjectService := service.NewCooperationProjectService(nil)
  68 + checkUndertakerQuery := &query.CheckUndertakerQuery{}
  69 + data, err := cooperationProjectService.CheckUndertaker(checkUndertakerQuery)
  70 + controller.Response(data, err)
  71 +}
  72 +
  73 +func (controller *CooperationProjectController) ListCooperationProject() {
  74 + cooperationProjectService := service.NewCooperationProjectService(nil)
  75 + listCooperationProjectQuery := &query.ListCooperationProjectQuery{}
  76 + offset, _ := controller.GetInt("offset")
  77 + listCooperationProjectQuery.Offset = offset
  78 + limit, _ := controller.GetInt("limit")
  79 + listCooperationProjectQuery.Limit = limit
  80 + data, err := cooperationProjectService.ListCooperationProject(listCooperationProjectQuery)
  81 + controller.Response(data, err)
  82 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + web.Router("/cooperation-projects/release-cooperation-project", &controllers.CooperationProjectController{}, "Post:ReleaseCooperationProject")
  10 + web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Post:CreateCooperationProject")
  11 + web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Put:UpdateCooperationProject")
  12 + web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Get:GetCooperationProject")
  13 + web.Router("/cooperation-projects/:cooperationProjectId", &controllers.CooperationProjectController{}, "Delete:RemoveCooperationProject")
  14 + web.Router("/cooperation-projects/search", &controllers.CooperationProjectController{}, "Post:SearchCooperationProject")
  15 + web.Router("/cooperation-projects/check", &controllers.CooperationProjectController{}, "Post:CheckUndertaker")
  16 + web.Router("/cooperation-projects/", &controllers.CooperationProjectController{}, "Get:ListCooperationProject")
  17 +}
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("判断当前勾选的承接对象是否存在用户", func() {
  14 + var cooperationProjectId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&cooperationProjectId),
  18 + "INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
  19 + "testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("判断当前勾选的承接对象是否存在用户", func() {
  23 + Context("", func() {
  24 + It("", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "cooperationProjectUndertakerType": "array",
  28 + "cooperationProjectId": "int64",
  29 + }
  30 + httpExpect.POST("/cooperation-projects/check").
  31 + WithJSON(body).
  32 + Expect().
  33 + Status(http.StatusOK).
  34 + JSON().
  35 + Object().
  36 + ContainsKey("code").ValueEqual("code", 0).
  37 + ContainsKey("msg").ValueEqual("msg", "ok").
  38 + ContainsKey("data").Value("data").Object()
  39 + })
  40 + })
  41 + })
  42 + AfterEach(func() {
  43 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  44 + Expect(err).NotTo(HaveOccurred())
  45 + })
  46 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/beego/beego/v2/server/web"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/application"
  12 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  13 + _ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/port/beego"
  14 +)
  15 +
  16 +func TestCooperationProject(t *testing.T) {
  17 + RegisterFailHandler(Fail)
  18 + RunSpecs(t, "Beego Port CooperationProject Correlations Test Case Suite")
  19 +}
  20 +
  21 +var handler http.Handler
  22 +var server *httptest.Server
  23 +
  24 +var _ = BeforeSuite(func() {
  25 + handler = web.BeeApp.Handlers
  26 + server = httptest.NewServer(handler)
  27 +})
  28 +
  29 +var _ = AfterSuite(func() {
  30 + server.Close()
  31 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + . "github.com/onsi/ginkgo"
  8 + . "github.com/onsi/gomega"
  9 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  10 +)
  11 +
  12 +var _ = Describe("创建共创项目服务", func() {
  13 + Describe("提交数据创建共创项目服务", func() {
  14 + Context("提交正确的新共创项目实体数据", func() {
  15 + It("返回共创项目实体数据", func() {
  16 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  17 + body := map[string]interface{}{
  18 + "cooperationProjectName": "string",
  19 + "cooperationProjectUndertakerType": "array",
  20 + "sponsorUid": "string",
  21 + "publisherUid": "string",
  22 + "cooperationProjectDescription": "string",
  23 + "companyId": "int64",
  24 + "orgId": "int64",
  25 + "userId": "int64",
  26 + }
  27 + httpExpect.POST("/cooperation-projects/").
  28 + WithJSON(body).
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object().
  36 + ContainsKey("cooperationProjectId").ValueNotEqual("cooperationProjectId", BeZero())
  37 + })
  38 + })
  39 + })
  40 + AfterEach(func() {
  41 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  42 + Expect(err).NotTo(HaveOccurred())
  43 + })
  44 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回共创项目服务", func() {
  14 + var cooperationProjectId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&cooperationProjectId),
  18 + "INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
  19 + "testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据cooperationProjectId参数返回共创项目实体", func() {
  23 + Context("传入有效的cooperationProjectId", func() {
  24 + It("返回共创项目实体数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/cooperation-projects/{cooperationProjectId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("返回共创项目服务列表", func() {
  14 + var cooperationProjectId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&cooperationProjectId),
  18 + "INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
  19 + "testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数返回共创项目实体列表", func() {
  23 + Context("传入有效的参数", func() {
  24 + It("返回共创项目实体数据列表", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.GET("/cooperation-projects/").
  27 + WithQuery("offset", "int").
  28 + WithQuery("limit", "int").
  29 + Expect().
  30 + Status(http.StatusOK).
  31 + JSON().
  32 + Object().
  33 + ContainsKey("code").ValueEqual("code", 0).
  34 + ContainsKey("msg").ValueEqual("msg", "ok").
  35 + ContainsKey("data").Value("data").Object().
  36 + ContainsKey("count").ValueEqual("count", 1).
  37 + ContainsKey("cooperationProjects").Value("cooperationProjects").Array()
  38 + })
  39 + })
  40 + })
  41 + AfterEach(func() {
  42 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  43 + Expect(err).NotTo(HaveOccurred())
  44 + })
  45 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("发布共创项目", func() {
  14 + var cooperationProjectId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&cooperationProjectId),
  18 + "INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
  19 + "testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("发布共创项目", func() {
  23 + Context("", func() {
  24 + It("", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "cooperationProjectName": "string",
  28 + "cooperationModeId": "int64",
  29 + "userId": "int64",
  30 + "userBaseId": "int64",
  31 + "orgId": "int64",
  32 + "orgName": "string",
  33 + "companyId": "int64",
  34 + "companyLogo": "string",
  35 + "companyName": "string",
  36 + "orgs": "array",
  37 + "departmentId": "int64",
  38 + "departmentName": "string",
  39 + "departmentNumber": "string",
  40 + "isOrganization": "boolean",
  41 + "roleId": "int64",
  42 + "roleName": "string",
  43 + "userAvatar": "string",
  44 + "userEmail": "string",
  45 + "userName": "string",
  46 + "userPhone": "string",
  47 + "userAccount": "string",
  48 + "userType": "int32",
  49 + "status": "int32",
  50 + "cooperationProjectUndertakerType": "array",
  51 + "cooperationProjectDescription": "string",
  52 + }
  53 + httpExpect.POST("/cooperation-projects/release-cooperation-project").
  54 + WithJSON(body).
  55 + Expect().
  56 + Status(http.StatusOK).
  57 + JSON().
  58 + Object().
  59 + ContainsKey("code").ValueEqual("code", 0).
  60 + ContainsKey("msg").ValueEqual("msg", "ok").
  61 + ContainsKey("data").Value("data").Object()
  62 + })
  63 + })
  64 + })
  65 + AfterEach(func() {
  66 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  67 + Expect(err).NotTo(HaveOccurred())
  68 + })
  69 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("移除共创项目服务", func() {
  14 + var cooperationProjectId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&cooperationProjectId),
  18 + "INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
  19 + "testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数移除共创项目服务", func() {
  23 + Context("传入有效的cooperationProjectId", func() {
  24 + It("返回被移除共创项目实体的数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.DELETE("/cooperation-projects/{cooperationProjectId}").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("查询共创项目", func() {
  14 + var cooperationProjectId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&cooperationProjectId),
  18 + "INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
  19 + "testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("查询共创项目", func() {
  23 + Context("", func() {
  24 + It("", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "pageNumber": "int32",
  28 + "pageSize": "int32",
  29 + "cooperationProjectName": "string",
  30 + "departmentName": "string",
  31 + "status": "int32",
  32 + "companyId": "int64",
  33 + "orgId": "int64",
  34 + "userId": "int64",
  35 + }
  36 + httpExpect.POST("/cooperation-projects/search").
  37 + WithJSON(body).
  38 + Expect().
  39 + Status(http.StatusOK).
  40 + JSON().
  41 + Object().
  42 + ContainsKey("code").ValueEqual("code", 0).
  43 + ContainsKey("msg").ValueEqual("msg", "ok").
  44 + ContainsKey("data").Value("data").Object()
  45 + })
  46 + })
  47 + })
  48 + AfterEach(func() {
  49 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  50 + Expect(err).NotTo(HaveOccurred())
  51 + })
  52 +})
  1 +package cooperation_project
  2 +
  3 +import (
  4 + "github.com/go-pg/pg/v10"
  5 + "net/http"
  6 +
  7 + "github.com/gavv/httpexpect"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/allied-creation/allied-creation-cooperation/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("更新共创项目服务", func() {
  14 + var cooperationProjectId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&cooperationProjectId),
  18 + "INSERT INTO cooperation_projects (cooperation_project_id, cooperation_project_number, cooperation_project_description, cooperation_project_name, cooperation_project_publish_time, cooperation_project_publisher, cooperation_project_sponsor, cooperation_project_undertaker_type, org, company, operator, operate_time, status, updated_at, deleted_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING cooperation_project_id",
  19 + "testCooperationProjectId", "testCooperationProjectNumber", "testCooperationProjectDescription", "testCooperationProjectName", "testCooperationProjectPublishTime", "testCooperationProjectPublisher", "testCooperationProjectSponsor", "testCooperationProjectUndertakerType", "testOrg", "testCompany", "testOperator", "testOperateTime", "testStatus", "testUpdatedAt", "testDeletedAt", "testCreatedAt")
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("提交数据更新共创项目服务", func() {
  23 + Context("提交正确的共创项目实体数据", func() {
  24 + It("返回更新后的共创项目实体数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "cooperationProjectName": "string",
  28 + "cooperationProjectUndertakerType": "array",
  29 + "sponsorUid": "string",
  30 + "publisherUid": "string",
  31 + "cooperationProjectDescription": "string",
  32 + "companyId": "int64",
  33 + "orgId": "int64",
  34 + "userId": "int64",
  35 + }
  36 + httpExpect.PUT("/cooperation-projects/{cooperationProjectId}").
  37 + WithJSON(body).
  38 + Expect().
  39 + Status(http.StatusOK).
  40 + JSON().
  41 + Object().
  42 + ContainsKey("code").ValueEqual("code", 0).
  43 + ContainsKey("msg").ValueEqual("msg", "ok").
  44 + ContainsKey("data").Value("data").Object().
  45 + ContainsKey("cooperationProjectId").ValueEqual("cooperationProjectId", cooperationProjectId)
  46 + })
  47 + })
  48 + })
  49 + AfterEach(func() {
  50 + _, err := pG.DB.Exec("DELETE FROM cooperation_projects WHERE true")
  51 + Expect(err).NotTo(HaveOccurred())
  52 + })
  53 +})