123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "cp-system-management-gateway/consts"
- "cp-system-management-gateway/errors"
- param_v1 "cp-system-management-gateway/param/v1"
- "cp-system-management-gateway/pb"
- "cp-system-management-gateway/pb/v1"
- "cp-system-management-gateway/utils"
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jaryhe/gopkgs/tasker/httptasker"
- "github.com/jaryhe/gopkgs/util"
- "net/http"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- )
- //
- // @Summary 创建机构
- // @Description 创建机构
- // @Tags 机构
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.CreateOrganizationBody true "机构信息"
- // @Success 200 {object} v1.CreateOrganizationResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/organization [post]
- func (c *Controller) CreateOrganization(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CreateOrganizationRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.CreateOrganizationBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.CreateOrganizationResponse{}
- rpcReq := &v1.CreateOrganizationRequest{
- Month:req.Month,
- OrganizationName:req.OrganizationName,
- IsDisable:req.IsDisable,
- }
- rpcRsp, err := pb.System.CreateOrganization(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.CreateOrganization"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data.OrganizationCode = rpcRsp.OrganizationCode
- ctx.JSON(http.StatusOK, resp)
- // 操作日志
- loginUid, userName, _ := utils.GetJwtIdFromCtx(ctx)
- logReq := OperationLogRequest{
- Module:consts.OperationModuleOrganization,
- Action:consts.OperationActionOrganizationAdd,
- Origin:nil,
- Target:req.CreateOrganizationBody,
- UserName:userName,
- Uid:loginUid,
- }
- OperationLogAdd(&logReq)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 修改机构
- // @Description 修改机构
- // @Tags 机构
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.UpdateOrganizationBody true "机构信息"
- // @Success 200 {object} v1.UpdateOrganizationResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/organization [put]
- func (c *Controller) UpdateOrganization(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.UpdateOrganizationRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.UpdateOrganizationBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.UpdateOrganizationResponse{}
- rpcReq := &v1.UpdateOrganizationRequest{
- Month:req.Month,
- OrganizationName:req.OrganizationName,
- IsDisable:req.IsDisable,
- OrganizationCode:req.OrganizationCode,
- }
- origin, err := pb.System.UpdateOrganization(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.UpdateOrganization"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- // 操作日志
- loginUid, userName, _ := utils.GetJwtIdFromCtx(ctx)
- logReq := OperationLogRequest{
- Module:consts.OperationModuleOrganization,
- Action:consts.OperationActionOrganizationUpdate,
- Origin:origin.Origin,
- Target:req.UpdateOrganizationBody,
- UserName:userName,
- Uid:loginUid,
- }
- OperationLogAdd(&logReq)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 获取机构列表
- // @Description 获取机构列表
- // @Tags 机构
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param filter query string false "过滤"
- // @Param page query int64 false " "
- // @Param page_size query int64 false " "
- // @Success 200 {object} v1.OrganizationListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/organization/list [get]
- func (c *Controller) OrganizationList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.OrganizationListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.OrganizationListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.OrganizationListResponse{}
- rpcReq := &v1.OrganizationListRequest{
- Page:req.Page,
- PageSize:req.PageSize,
- Filter:req.Filter,
- }
- rpcRsp, err := pb.System.OrganizationList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.OrganizationList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.Organization, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 创建机构超级管理员
- // @Description 创建机构超级管理员
- // @Tags 机构
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.CreateOrganizationUserBody true "机构信息"
- // @Success 200 {object} v1.CreateOrganizationUserResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/organization/user [post]
- func (c *Controller) CreateOrganizationUser(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CreateOrganizationUserRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.CreateOrganizationUserBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.CreateOrganizationUserResponse{}
- rpcReq := &v1.CreateOrganizationUserRequest{
- OrganizationCode:req.OrganizationCode,
- Username:req.Username,
- Password:req.Password,
- Email:req.Email,
- Phone:req.Phone,
- }
- rpcRsp, err := pb.System.CreateOrganizationUser(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.CreateOrganizationUser"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data.Uid = rpcRsp.Uid
- ctx.JSON(http.StatusOK, resp)
- // 操作日志
- loginUid, userName, _ := utils.GetJwtIdFromCtx(ctx)
- logReq := OperationLogRequest{
- Module:consts.OperationModuleOrganization,
- Action:consts.OperationActionOrganizationUserAdd,
- Origin:nil,
- Target:req.CreateOrganizationUserBody,
- UserName:userName,
- Uid:loginUid,
- }
- OperationLogAdd(&logReq)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 修改机构超级管理员
- // @Description 修改机构超级管理员
- // @Tags 机构
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.OrganizationUserUpdateBody true " "
- // @Success 200 {object} v1.OrganizationUserUpdateResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/organization/user [put]
- func (c *Controller) OrganizationUserUpdate(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.OrganizationUserUpdateRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.OrganizationUserUpdateBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.OrganizationUserUpdateResponse{}
- rpcReq := &v1.OrganizationUserUpdateRequest{
- OrganizationCode:req.OrganizationCode,
- Username:req.Username,
- Email:req.Email,
- Phone:req.Phone,
- Id:req.Id,
- Password:req.Password,
- }
- origin, err := pb.System.OrganizationUserUpdate(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.OrganizationUserUpdate"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- // 操作日志
- loginUid, userName, _ := utils.GetJwtIdFromCtx(ctx)
- origin.Origin.Password = "******"
- req.OrganizationUserUpdateBody.Password = "******"
- logReq := OperationLogRequest{
- Module:consts.OperationModuleOrganization,
- Action:consts.OperationActionOrganizationUserUpdate,
- Origin:origin.Origin,
- Target:req.OrganizationUserUpdateBody,
- UserName:userName,
- Uid:loginUid,
- }
- OperationLogAdd(&logReq)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- /*
- //
- // @Summary 修改机构超级管理员密码
- // @Description 修改机构超级管理员密码
- // @Tags 机构
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param body body v1.OrganizationUserResetPasswordBody true " "
- // @Success 200 {object} v1.OrganizationUserResetPasswordResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/organization/user_password [put]
- func (c *Controller) OrganizationUserResetPassword(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.OrganizationUserResetPasswordRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.OrganizationUserResetPasswordBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.OrganizationUserResetPasswordResponse{}
- rpcReq := &v1.OrganizationUserResetPasswordRequest{
- OrganizationCode:req.OrganizationCode,
- Id:req.Id,
- Password:req.Password,
- }
- _, err := pb.System.OrganizationUserResetPassword(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.OrganizationUserResetPassword"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- ctx.JSON(http.StatusOK, resp)
- loginUid, userName, _ := utils.GetJwtIdFromCtx(ctx)
- req.Password = "******"
- logReq := OperationLogRequest{
- Module:consts.OperationModuleOrganization,
- Action:consts.OperationActionOrganizationUserResetPassword,
- Origin:nil,
- Target:req.OrganizationUserResetPasswordBody,
- UserName:userName,
- Uid:loginUid,
- }
- OperationLogAdd(&logReq)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- */
- //
- // @Summary 获取机构超级管理员列表
- // @Description 获取机构超级管理员列表
- // @Tags 机构
- // @Accept json
- // @Produce json
- // @Param token header string true "token"
- // @Param page query int64 false " "
- // @Param page_size query int64 false " "
- // @Param organization_code query string true "机构代码"
- // @Success 200 {object} v1.OrganizationUserListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/organization/user_list [get]
- func (c *Controller) OrganizationUserList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.OrganizationUserListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.OrganizationUserListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- // 响应数据
- resp := param_v1.OrganizationUserListResponse{}
- rpcReq := &v1.OrganizationUserListRequest{
- Page:req.Page,
- PageSize:req.PageSize,
- OrganizationCode:req.OrganizationCode,
- }
- rpcRsp, err := pb.System.OrganizationUserList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.OrganizationUserList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.OrganizationUserItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|