sys_department.api 4.6 KB

syntax = "v1"

info(
    title: "xx实例"
    desc: "xx实例"
    author: "author"
    email: "email"
    version: "v1"
)

@server(
    prefix: v1
    group: sys_department
    jwt: JwtAuth
)
service Core {
	@doc  "详情"
    @handler sys_departmentGet
    get /sys_department/:id (SysDepartmentGetRequest) returns (SysDepartmentGetResponse)
    @doc  "保存"
	@handler sys_departmentSave
    post /sys_department (SysDepartmentSaveRequest) returns (SysDepartmentSaveResponse)
    @doc  "删除"
	@handler sys_departmentDelete
    delete /sys_department/:id (SysDepartmentDeleteRequest) returns (SysDepartmentDeleteResponse)
    @doc  "更新"
	@handler sys_departmentUpdate
    put /sys_department/:id (SysDepartmentUpdateRequest) returns (SysDepartmentUpdateResponse)
    @doc  "搜索"
	@handler sys_departmentSearch
    post /sys_department/search (SysDepartmentSearchRequest) returns (SysDepartmentSearchResponse)
}

type (
    SysDepartmentGetRequest {
		Id int64 `path:"id"`
	}
    SysDepartmentGetResponse struct{
		SysDepartment SysDepartmentItem `json:"sys_department"`
    }

	SysDepartmentSaveRequest struct{
		SysDepartment SysDepartmentItem `json:"sys_department"`
    }
    SysDepartmentSaveResponse struct{}

	SysDepartmentDeleteRequest struct{
        Id int64 `path:"id"`
    }
    SysDepartmentDeleteResponse struct{}

	SysDepartmentUpdateRequest struct{
		Id int64 `path:"id"`
        SysDepartment SysDepartmentItem `json:"sys_department"`
    }
    SysDepartmentUpdateResponse struct{}

 	SysDepartmentSearchRequest struct{
         Page int  `json:"page"`
         Size int  `json:"size"`
    }
    SysDepartmentSearchResponse{
        List []SysDepartmentItem  `json:"list"`
        Total int64 `json:"total"`
    }
	SysDepartmentItem struct{
	
	}
)

// logic CRUD
// Save
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.SysDepartment
	//)
	//// 唯一判断

	//dm = NewDomainSysDepartment(req.SysDepartment)
	//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
	//	dm, err = l.svcCtx.SysDepartmentRepository.Insert(l.ctx, conn, dm)
	//	return err
	//}, true); err != nil {
	//	return nil, xerr.NewErrMsg("保存失败")
	//}
	////resp = &types.SysDepartmentSaveResponse{}
	//return

//func NewDomainSysDepartment(item types.SysDepartmentItem) *domain.SysDepartment {
//	return &domain.SysDepartment{

//	}
//}
//
//func NewTypesSysDepartment(item *domain.SysDepartment) types.SysDepartmentItem {
//	return types.SysDepartmentItem{
//		Id:     item.Id,
//	}
//}

// Get
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.SysDepartment
	//)
	//// 货号唯一
	//if dm, err = l.svcCtx.SysDepartmentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
	//	return nil, xerr.NewErrMsgErr("不存在", err)
	//}
	//resp = &types.SysDepartmentGetResponse{
	//	SysDepartment: NewTypesSysDepartment(dm),
	//}
	//return

// Delete
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.SysDepartment
	//)
	//if dm, err = l.svcCtx.SysDepartmentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
	//	return nil, xerr.NewErrMsgErr("不存在", err)
	//}
	//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
	//	if dm, err = l.svcCtx.SysDepartmentRepository.Delete(l.ctx, conn, dm); err != nil {
	//		return err
	//	}
	//	return nil
	//}, true); err != nil {
	//	return nil, xerr.NewErrMsgErr("移除失败", err)
	//}
	//return

// Search
	//var (
	//	conn  = l.svcCtx.DefaultDBConn()
	//	dms   []*domain.SysDepartment
	//	total int64
	//)
	//
	//queryOptions := domain.NewQueryOptions().WithOffsetLimit(req.Page, req.Size).
	//	WithKV("", "")

	//total, dms, err = l.svcCtx.SysDepartmentRepository.Find(l.ctx, conn, queryOptions)
	//list := make([]types.SysDepartmentItem, 0)
	//for i := range dms {
	//	list = append(list, NewTypesSysDepartment(dms[i]))
	//}
	//resp = &types.SysDepartmentSearchResponse{
	//	List:  list,
	//	Total: total,
	//}
	//return

// Update
	//var (
	//	conn = l.svcCtx.DefaultDBConn()
	//	dm   *domain.SysDepartment
	//)
	//if dm, err = l.svcCtx.SysDepartmentRepository.FindOne(l.ctx, conn, req.Id); err != nil {
	//	return nil, xerr.NewErrMsgErr("不存在", err)
	//}
	//// 不可编辑判断
	
	//// 赋值

	//// 更新
	//if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
	//	dm, err = l.svcCtx.SysDepartmentRepository.UpdateWithVersion(l.ctx, conn, dm)
	//	return err
	//}, true); err != nil {
	//	return nil, xerr.NewErrMsg("更新失败")
	//}
	//resp = &types.SysDepartmentUpdateResponse{}
	//return