作者 tangxuhui
package service
import (
"errors"
"time"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
... ... @@ -30,7 +29,7 @@ func (srv AuthService) AuthLogin(loginCommand *command.LoginCommand) (interface{
Phone: loginCommand.Phone,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "系统错误")
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
switch loginCommand.GrantType {
case "signInPassword":
... ... @@ -38,7 +37,7 @@ func (srv AuthService) AuthLogin(loginCommand *command.LoginCommand) (interface{
case "signInCaptcha":
result, err = srv.SignInCaptcha(loginCommand.Phone, loginCommand.Captcha)
default:
err = errors.New("登录方式无法解析")
err = application.ThrowError(application.TRANSACTION_ERROR, "登录方式无法解析")
}
return result, err
}
... ...
... ... @@ -17,7 +17,7 @@ type CreateCooperationProjectCommand struct {
// 共创项目名称
CooperationProjectName string `json:"cooperationProjectName" valid:"Required"`
// 共创发起人id
CooperationProjectSponsor int `json:"cooperationProjectSponsor,string,"`
CooperationProjectSponsor int `json:"cooperationProjectSponsor"`
// 项目承接对象
CooperationProjectUndertakerType []int `json:"cooperationProjectUndertakerType"`
// 共创项目描述
... ...
... ... @@ -13,9 +13,9 @@ type UpdateCooperationProjectCommand struct {
// 共创项目ID
CooperationProjectId string `json:"cooperationProjectId,string" valid:"Required"`
// 模式编码,唯一确定
CooperationModeNumber string `json:"cooperationModeNumber" valid:"Required"`
//CooperationModeNumber string `json:"cooperationModeNumber" valid:"Required"`
// 组织ID
OrgId string `json:"orgId" valid:"Required"`
OrgId int64 `json:"departmentId,string" valid:"Required"`
// 共创项目名称
CooperationProjectName string `json:"cooperationProjectName" valid:"Required"`
// 共创发起人id
... ...
... ... @@ -28,6 +28,7 @@ func (srv CooperationProjectService) CreateCooperationProject(createCooperationP
}
result, err := creationCooperationGateway.CooperationProjectAdd(allied_creation_cooperation.ReqCooperationProjectAdd{
CooperationProjectDescription: createCooperationProjectCommand.CooperationProjectDescription,
CooperationModeNumber: createCooperationProjectCommand.CooperationModeNumber,
CooperationProjectName: createCooperationProjectCommand.CooperationProjectName,
PublisherUid: int(createCooperationProjectCommand.Operator.UserId),
SponsorUid: createCooperationProjectCommand.CooperationProjectSponsor,
... ... @@ -72,14 +73,15 @@ func (srv CooperationProjectService) UpdateCooperationProject(updateCooperationP
})
}
_, err := creationCooperationGateway.CooperationProjectUpdate(allied_creation_cooperation.ReqCooperationProjectUpdate{
CooperationProjectId: updateCooperationProjectCommand.CooperationProjectId,
CooperationProjectName: updateCooperationProjectCommand.CooperationProjectName,
CooperationModeNumber: updateCooperationProjectCommand.CooperationModeNumber,
CooperationProjectId: updateCooperationProjectCommand.CooperationProjectId,
CooperationProjectName: updateCooperationProjectCommand.CooperationProjectName,
//CooperationModeNumber: updateCooperationProjectCommand.CooperationModeNumber,
CooperationProjectUndertakerType: updateCooperationProjectCommand.CooperationProjectUndertakerType,
SponsorUid: updateCooperationProjectCommand.CooperationProjectSponsor,
PublisherUid: strconv.Itoa(int(updateCooperationProjectCommand.Operator.UserId)),
CooperationProjectDescription: updateCooperationProjectCommand.CooperationProjectDescription,
Attachment: images,
OrgId: updateCooperationProjectCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -116,12 +118,12 @@ func (srv CooperationProjectService) SearchCooperationProject(projectQuery *comm
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var dataList []dto.CooperationProjectItem
for i := range result.List {
item := dto.ToCooperationProjectItem(&result.List[i])
dataList = append(dataList, *item)
}
return int(result.Total), dataList, nil
//var dataList []dto.CooperationProjectItem
//for i := range result.List {
// item := dto.ToCooperationProjectItem(&result.List[i])
// dataList = append(dataList, *item)
//}
return int(result.Total), result.List, nil
}
// PersonSearchCooperationProject 共创用户获取共创项目列表
... ... @@ -137,10 +139,10 @@ func (srv CooperationProjectService) PersonSearchCooperationProject(projectQuery
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var dataList []dto.CooperationProjectItem
for i := range result.List {
item := dto.ToCooperationProjectItem(&result.List[i])
dataList = append(dataList, *item)
}
return int(result.Total), dataList, nil
//var dataList []dto.CooperationProjectItem
//for i := range result.List {
// item := dto.ToCooperationProjectItem(&result.List[i])
// dataList = append(dataList, *item)
//}
return int(result.Total), result, nil
}
... ...
... ... @@ -42,7 +42,7 @@ func (srv AuthService) SignInPassword(account string, password string) (interfac
Phone: account,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
ltoken := domain.LoginToken{
UserId: 0,
... ... @@ -52,7 +52,7 @@ func (srv AuthService) SignInPassword(account string, password string) (interfac
}
authcode, err := ltoken.GenerateAuthCode()
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
result := map[string]string{
"authCode": authcode,
... ...
... ... @@ -72,11 +72,11 @@ func (cooperationApplicationService *CooperationApplicationService) ListCooperat
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var dataList []dto.CooperationApplicationItem
for i := range result.Gride.List {
item := dto.ToCooperationApplicationItem(&result.Gride.List[i])
for i := range result.Grid.List {
item := dto.ToCooperationApplicationItem(&result.Grid.List[i])
dataList = append(dataList, *item)
}
return int64(result.Gride.Total), dataList, nil
return int64(result.Grid.Total), dataList, nil
}
func NewCooperationApplicationService(options map[string]interface{}) *CooperationApplicationService {
... ...
... ... @@ -11,11 +11,11 @@ type UpdateCooperationProjectCommand struct {
//操作人
Operator domain.Operator `json:"-"`
// 共创项目ID
CooperationProjectId string `json:"cooperationProjectId,string" valid:"Required"`
CooperationProjectId string `json:"cooperationProjectId" valid:"Required"`
// 模式编码,唯一确定
CooperationModeNumber string `json:"cooperationModeNumber" valid:"Required"`
// 组织ID
OrgId string `json:"orgId" valid:"Required"`
OrgId int64 `json:"departmentId,string" valid:"Required"`
// 共创项目名称
CooperationProjectName string `json:"cooperationProjectName" valid:"Required"`
// 共创发起人id
... ...
... ... @@ -30,7 +30,7 @@ type CooperationProjectInfo struct {
CooperationProjectPublishTime time.Time `json:"cooperationProjectPublishTime"`
CreatedAt time.Time `json:"createdAt"`
CooperationProjectSponsor struct {
UsersId int `json:"userId"`
UserId int `json:"userId,string"`
UsersName string `json:"userName"`
UsersCode string `json:"userCode"`
UserInfo struct {
... ... @@ -68,7 +68,7 @@ func ToCooperationProjectInfo(param *allied_creation_cooperation.CooperationProj
data.CooperationProjectSponsor.UsersCode = param.CooperationProjectSponsor.UserInfo.UsersCode
data.CooperationProjectSponsor.UsersName = param.CooperationProjectSponsor.UserInfo.UsersName
data.CooperationProjectSponsor.UsersId = param.CooperationProjectSponsor.UsersId
data.CooperationProjectSponsor.UserId = param.CooperationProjectSponsor.UsersId
data.CooperationProjectSponsor.UserInfo = param.CooperationProjectSponsor.UserInfo
return &data
}
... ...
... ... @@ -89,8 +89,8 @@ func (cooperationProjectService *CooperationProjectService) GetCooperationProjec
var (
applications []dto.CooperationApplicationItem
)
for i := range resultApplication.Gride.List {
item := dto.ToCooperationApplicationItem(&resultApplication.Gride.List[i])
for i := range resultApplication.Grid.List {
item := dto.ToCooperationApplicationItem(&resultApplication.Grid.List[i])
applications = append(applications, *item)
}
data := map[string]interface{}{
... ... @@ -117,15 +117,15 @@ func (cooperationProjectService *CooperationProjectService) ListCooperationProje
if err != nil {
return 0, nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
var (
dataList = []dto.CooperationProjectInfo{}
)
for i := range result.List {
item := dto.ToCooperationProjectInfo(&result.List[i])
dataList = append(dataList, *item)
}
return result.Total, dataList, nil
//
//var (
// dataList = []dto.CooperationProjectInfo{}
//)
//for i := range result.List {
// item := dto.ToCooperationProjectInfo(&result.List[i])
// dataList = append(dataList, *item)
//}
return int64(result.Total), result.List, nil
}
// 更新共创项目管理
... ... @@ -149,6 +149,9 @@ func (cooperationProjectService *CooperationProjectService) UpdateCooperationPro
PublisherUid: strconv.Itoa(int(updateCooperationProjectCommand.Operator.UserId)),
CooperationProjectDescription: updateCooperationProjectCommand.CooperationProjectDescription,
Attachment: images,
UserId: updateCooperationProjectCommand.Operator.UserId,
UserBaseId: updateCooperationProjectCommand.Operator.UserBaseId,
OrgId: updateCooperationProjectCommand.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ...
package dto
import "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
type DepartmentUsersDto struct {
Departments []*Department `json:"departments"`
}
type Department struct {
DepartmentID int64 `json:"departmentId,string"`
DepartmentName string `json:"departmentName"`
Users []User `json:"users"`
}
type User struct {
UserID int `json:"userId,string"`
UserInfo map[string]interface{} `json:"userInfo"`
}
func (dto *DepartmentUsersDto) LoadDto(subDepartment *allied_creation_user.DataOrgGetSubDepartment, userSearch *allied_creation_user.DataUserSearch) error {
var mapDepartment = make(map[int64]*Department)
for i := range subDepartment.Orgs {
org := subDepartment.Orgs[i]
dep := &Department{
DepartmentID: int64(org.OrgID),
DepartmentName: org.OrgName,
Users: make([]User, 0),
}
dto.Departments = append(dto.Departments, dep)
mapDepartment[dep.DepartmentID] = dep
}
for i := range userSearch.Users {
user := userSearch.Users[i]
if user.Department == nil {
continue
}
if v, ok := mapDepartment[int64(user.Department.DepartmentId)]; ok {
v.Users = append(v.Users, User{
UserID: user.UserId,
UserInfo: map[string]interface{}{
"userName": user.UserInfo.UserName,
},
})
}
}
return nil
}
... ...
package query
import (
"fmt"
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)
//获取自定义菜单列表
type DepartmentsUsersQuery struct {
//操作人
Operator domain.Operator `json:"-"`
}
func (departmentsUsersQuery *DepartmentsUsersQuery) Valid(validation *validation.Validation) {
}
func (departmentsUsersQuery *DepartmentsUsersQuery) ValidateQuery() error {
valid := validation.Validation{}
b, err := valid.Valid(departmentsUsersQuery)
if err != nil {
return err
}
if !b {
for _, validErr := range valid.Errors {
return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
}
}
return nil
}
... ...
... ... @@ -147,6 +147,33 @@ func (orgsService *OrgsService) OrgGetSubDepartment(orgGetQuery *query.OrgGetSub
}, nil
}
//DepartmentsUsers 部门用户列表
func (orgsService OrgsService) DepartmentsUsers(departmentsUsersQuery *query.DepartmentsUsersQuery) (interface{}, error) {
creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
departmentsUsersQuery.Operator)
orgs, err := creationUserGateway.OrgGetSubDepartment(allied_creation_user.ReqOrgGetSubDepartment{
OrgId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
users, err := creationUserGateway.UserSearch(allied_creation_user.ReqUserSearch{
//Offset: 0,
//Limit: 999,
CompanyId: departmentsUsersQuery.Operator.CompanyId,
OrganizationId: departmentsUsersQuery.Operator.OrgId,
})
if err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
departmentUsersDto := &dto.DepartmentUsersDto{}
if err := departmentUsersDto.LoadDto(orgs, users); err != nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
}
return departmentUsersDto, nil
}
func NewOrgsService(options map[string]interface{}) *OrgsService {
newOrgsService := &OrgsService{}
return newOrgsService
... ...
... ... @@ -104,7 +104,7 @@ func (gateway HttplibAlliedCreationCooperation) CooperationProjectGet(param ReqC
// CooperationProjectUpdate 更新共创项目
func (gateway HttplibAlliedCreationCooperation) CooperationProjectUpdate(param ReqCooperationProjectUpdate) (*DataCooperationProjectUpdate, error) {
url := gateway.baseUrL + "/cooperation-projects/{cooperationProjectId}"
url := gateway.baseUrL + "/cooperation-projects/" + param.CooperationProjectId
method := "PUT"
req := gateway.CreateRequest(url, method)
log.Logger.Debug("向业务模块请求数据:更新共创项目。", map[string]interface{}{
... ...
... ... @@ -227,10 +227,10 @@ type (
}
DataCooperationApplicationSearch struct {
Gride struct {
Grid struct {
Total int `json:"total"`
List []CooperationApplication `json:"list"`
} `json:"gride"`
} `json:"grid"`
}
)
... ...
... ... @@ -2,6 +2,7 @@ package allied_creation_cooperation
import (
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/util/jtime"
"time"
)
... ... @@ -51,7 +52,7 @@ type CooperationProject struct {
UsersId int `json:"userId,string"`
} `json:"userInfo"`
} `json:"cooperationProjectSponsor"` //项目发起人
CooperationProjectUndertakerType []int `json:"cooperationProjectUndertakerType"` //共创合约承接对象,1员工,2共创用户,3公开
CooperationProjectUndertakerType []int `json:"cooperationProjectUndertakerTypes"` //共创合约承接对象,1员工,2共创用户,3公开
Department struct {
DepartmentNumber string `json:"departmentNumber"`
DepartmentId int `json:"departmentId,string,"`
... ... @@ -94,7 +95,7 @@ type (
}
DataCooperationProjectGet struct {
CooperationProject CooperationProject `json:"cooperationProject"`
CooperationProject
}
)
... ... @@ -115,6 +116,12 @@ type (
// 共创项目描述
CooperationProjectDescription string `json:"cooperationProjectDescription"`
Attachment []domain.Attachment `json:"attachment"`
// 组织机构ID
OrgId int64 `cname:"组织机构ID" json:"orgId,string" valid:"Required"`
// 用户ID,通过集成REST上下文获取,可翻译成发起人、承接人、推荐人、业务员
UserId int64 `cname:"用户ID" json:"userId,string" valid:"Required"`
// 用户基础数据id
UserBaseId int64 `cname:"用户基础数据ID" json:"userBaseId,string" valid:"Required"`
}
DataCooperationProjectUpdate struct {
... ... @@ -157,8 +164,86 @@ type (
}
DataCooperationProjectSearch struct {
Total int64 `json:"total"`
List []CooperationProject `json:"cooperationProjects"`
//Total int64 `json:"total"`
//List []CooperationProject `json:"cooperationProjects"`
List []struct {
CooperationProjectID string `json:"cooperationProjectId"`
CooperationProjectNumber string `json:"cooperationProjectNumber"`
CooperationProjectDescription string `json:"cooperationProjectDescription"`
CooperationProjectName string `json:"cooperationProjectName"`
CooperationProjectPublishTime jtime.TimeToUnixMsec `json:"cooperationProjectPublishTime"`
CooperationProjectPublisher struct {
UserID string `json:"userId"`
UserBaseID string `json:"userBaseId"`
Department interface{} `json:"department"`
UserInfo struct {
UserAvatar string `json:"userAvatar"`
UserEmail string `json:"userEmail"`
UserName string `json:"userName"`
UserPhone string `json:"userPhone"`
UserAccount string `json:"userAccount"`
} `json:"userInfo"`
//UserType int `json:"userType"`
//UserName string `json:"userName"`
//UserPhone string `json:"userPhone"`
//Status int `json:"status"`
} `json:"cooperationProjectPublisher"`
CooperationProjectSponsor struct {
UserID string `json:"userId"`
UserBaseID string `json:"userBaseId"`
Department interface{} `json:"department"`
UserInfo struct {
UserAvatar string `json:"userAvatar"`
UserEmail string `json:"userEmail"`
UserName string `json:"userName"`
UserPhone string `json:"userPhone"`
UserAccount string `json:"userAccount"`
} `json:"userInfo"`
//UserType int `json:"userType"`
//UserName string `json:"userName"`
//UserPhone string `json:"userPhone"`
//Status int `json:"status"`
} `json:"cooperationProjectSponsor"`
Department struct {
DepartmentID string `json:"departmentId"`
DepartmentName string `json:"departmentName"`
DepartmentNumber string `json:"departmentNumber"`
//IsOrganization bool `json:"isOrganization"`
} `json:"department"`
CooperationProjectUndertakerTypes []int `json:"cooperationProjectUndertakerTypes"`
Org struct {
OrgID string `json:"orgId"`
OrgName string `json:"orgName"`
} `json:"org"`
Attachment interface{} `json:"attachment"`
Company struct {
CompanyID string `json:"companyId"`
CompanyLogo string `json:"companyLogo"`
CompanyName string `json:"companyName"`
} `json:"company"`
Operator struct {
UserID string `json:"userId"`
UserBaseID string `json:"userBaseId"`
Department interface{} `json:"department"`
UserInfo struct {
UserAvatar string `json:"userAvatar"`
UserEmail string `json:"userEmail"`
UserName string `json:"userName"`
UserPhone string `json:"userPhone"`
UserAccount string `json:"userAccount"`
} `json:"userInfo"`
//UserType int `json:"userType"`
//UserName string `json:"userName"`
//UserPhone string `json:"userPhone"`
//Status int `json:"status"`
} `json:"operator"`
//OperateTime time.Time `json:"operateTime"`
Status int `json:"status"`
//UpdatedAt time.Time `json:"updatedAt"`
//DeletedAt time.Time `json:"deletedAt"`
//CreatedAt time.Time `json:"createdAt"`
} `json:"list"`
Total int `json:"total"`
}
)
... ...
... ... @@ -22,6 +22,15 @@ func (controller *baseController) returnPageListData(count int64, data interface
controller.Response(dataMap, err)
}
func (controller *baseController) returnListData(count int64, data interface{}, err error) {
dataMap := map[string]interface{}{
"total": count,
//"pageNumber": pageNumber,
"list": data,
}
controller.Response(dataMap, err)
}
func (controller *baseController) GetUserId() int64 {
return 1
}
... ...
... ... @@ -207,8 +207,8 @@ func (controller *CooperationController) SearchCooperationProject() {
return
}
cmd.Operator = controller.GetOperator()
_, data, err := svr.SearchCooperationProject(cmd)
controller.Response(data, err)
total, data, err := svr.SearchCooperationProject(cmd)
controller.returnPageListData(int64(total), data, err, cmd.PageNumber)
}
func (controller *CooperationController) PersonSearchCooperationProject() {
... ...
... ... @@ -20,6 +20,14 @@ func (controller *baseController) returnPageListData(count int64, data interface
controller.Response(dataMap, err)
}
func (controller *baseController) returnListData(count int64, data interface{}, err error) {
dataMap := map[string]interface{}{
"total": count,
"list": data,
}
controller.Response(dataMap, err)
}
func (controller *baseController) GetOperator() domain.Operator {
token := controller.Ctx.Input.Header("X-Mmm-Accesstoken")
loginToken := &domain.LoginToken{}
... ...
... ... @@ -82,8 +82,8 @@ func (controller *CooperationModeController) ListCooperationMode() {
listCooperationModeQuery.Operator = controller.GetOperator()
listCooperationModeQuery.PageNumber = 1
listCooperationModeQuery.PageSize = 999
_, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery)
controller.Response(data, err)
cnt, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery)
controller.returnListData(cnt, data, err)
}
func (controller *CooperationModeController) EnableCooperationMode() {
... ...
... ... @@ -82,3 +82,16 @@ func (controller *OrgsController) OrgGetSubDepartment() {
data, err := orgsService.OrgGetSubDepartment(orgGetSubDepartmentQuery)
controller.Response(data, err)
}
func (controller *OrgsController) DepartmentUsers() {
orgService := service.OrgsService{}
departmentsUsersQuery := &query.DepartmentsUsersQuery{}
err := controller.Unmarshal(departmentsUsersQuery)
if err != nil {
controller.Response(nil, err)
return
}
departmentsUsersQuery.Operator = controller.GetOperator()
data, err := orgService.DepartmentsUsers(departmentsUsersQuery)
controller.Response(data, err)
}
... ...
... ... @@ -2,7 +2,6 @@ package routers
import (
"github.com/beego/beego/v2/server/web"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
)
... ... @@ -13,5 +12,5 @@ func init() {
web.Router("/v1/web/orgs/:orgId", &web_client.OrgsController{}, "Get:OrgGet")
web.Router("/v1/web/orgs/enable", &web_client.OrgsController{}, "Post:OrgEnable")
web.Router("/v1/web/orgs/departments", &web_client.OrgsController{}, "Post:OrgGetSubDepartment")
web.Router("/v1/web/orgs/department-users", &mobile_client.OrgController{}, "Post:DepartmentUsers")
web.Router("/v1/web/orgs/department-users", &web_client.OrgsController{}, "Post:DepartmentUsers")
}
... ...
... ... @@ -24,3 +24,26 @@ func (t UnixTimeSecond) UnmarshalJSON(v []byte) error {
t = UnixTimeSecond(time.Unix(int64(number), 0))
return nil
}
type TimeToUnixMsec int64
// MarshalJSON implements json.Marshaler.
func (t TimeToUnixMsec) MarshalJSON() ([]byte, error) {
stamp := fmt.Sprintf("%d", t)
return []byte(stamp), nil
}
// MarshalJSON implements json.Unmarshaler.
func (t *TimeToUnixMsec) UnmarshalJSON(v []byte) error {
if len(v) < 2 {
*t = 0
return nil
}
str := string(v[1 : len(v)-1])
number, err := time.Parse(time.RFC3339, str)
if err != nil {
return fmt.Errorf("时间类型需要使用时间戳传参:%w", err)
}
*t = TimeToUnixMsec(number.Unix() * 1000)
return nil
}
... ...