telco_server/app/admin/apis/bus_apis/a_contract.go

282 lines
6.9 KiB
Go

package bus_apis
import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"github.com/go-admin-team/go-admin-core/sdk/api"
"go-admin/app/admin/models/bus_models"
"go-admin/app/admin/service/bus_service"
"go-admin/tools/app"
"net/http"
)
type ContractApi struct {
api.Api
}
// CreateContract 新建合同
// @Summary 新建合同
// @Tags 合同管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.CreateContractReq true "新建合同模型"
// @Success 200 {object} bus_models.CreateContractResp
// @Router /api/v1/contract/create [post]
func (e *ContractApi) CreateContract(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.CreateContractReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
resp, err := s.CreateContract(c, req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, resp, "新增成功")
return
}
// EditContract 编辑合同信息
// @Summary 编辑合同信息
// @Tags 合同管理
// @Produce json
// @Accept json
// @Param request body bus_models.EditContractReq true "编辑合同信息"
// @Success 200 {object} map[string]interface{} "成功返回"
// @Failure 400 {object} map[string]interface{} "请求参数错误"
// @Failure 500 {object} map[string]interface{} "服务器错误"
// @Router /api/v1/contract/edit [post]
func (e *ContractApi) EditContract(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.EditContractReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 调用服务层逻辑
err = s.EditContract(req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, "", "合同信息更新成功")
return
}
// ContractList 获取合同列表
// @Summary 获取合同列表
// @Tags 合同管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.ListContractReq true "合同列表请求参数"
// @Success 200 {object} bus_models.ListContractResp
// @Router /api/v1/contract/list [post]
func (e *ContractApi) ContractList(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.ListContractReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
resp, err := s.ListContracts(req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, resp, "查询成功")
return
}
// ContractDetail 获取合同详情
// @Summary 获取合同详情
// @Tags 合同管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.ContractDetailReq true "合同详情请求参数"
// @Success 200 {object} bus_models.ContractDetailResp
// @Router /api/v1/contract/detail [post]
func (e *ContractApi) ContractDetail(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.ContractDetailReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
resp, err := s.GetContractDetail(req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, resp, "查询成功")
return
}
// EditContractRemark 编辑合同备注
// @Summary 编辑合同备注
// @Tags 合同管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.EditContractRemarkReq true "编辑合同备注请求参数"
// @Success 200 {string} string "备注更新成功"
// @Router /api/v1/contract/remark/edit [post]
func (e *ContractApi) EditContractRemark(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.EditContractRemarkReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
if err := s.UpdateContractRemark(req); err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, "", "备注更新成功")
return
}
// InvalidContract 作废合同
// @Summary 作废合同
// @Tags 合同管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.InvalidContractReq true "作废合同请求参数"
// @Success 200 {string} string "合同已作废"
// @Router /api/v1/contract/invalid [post]
func (e *ContractApi) InvalidContract(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.InvalidContractReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
if err := s.InvalidateContract(req); err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, "", "合同已作废")
return
}
// DeleteContract 删除合同
// @Summary 删除合同
// @Tags 合同管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.DeleteContractReq true "删除合同请求参数"
// @Success 200 {string} string "合同已删除"
// @Router /api/v1/contract/delete [post]
func (e *ContractApi) DeleteContract(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.DeleteContractReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
if err = s.RemoveContract(req); err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, "", "合同已删除")
return
}
// GetContractDownloadLink 获取合同下载链接
// @Summary 获取合同下载链接
// @Tags 合同管理-V1.0.0
// @Produce json
// @Accept json
// @Param request body bus_models.GetContractDownloadLinkReq true "获取合同下载链接请求"
// @Success 200 {object} bus_models.GetContractDownloadLinkResp "返回下载链接"
// @Failure 400 {object} map[string]interface{} "请求参数错误"
// @Failure 500 {object} map[string]interface{} "服务器错误"
// @Router /api/v1/contract/download [post]
func (e *ContractApi) GetContractDownloadLink(c *gin.Context) {
s := bus_service.ContractService{}
var req bus_models.GetContractDownloadLinkReq
err := e.MakeContext(c).
MakeOrm().
Bind(&req, binding.JSON).
MakeService(&s.Service).
Errors
if err != nil {
e.Logger.Error(err)
e.Error(500, err, err.Error())
return
}
// 调用服务层逻辑
resp, err := s.GetContractDownloadLink(req)
if err != nil {
app.Error(c, http.StatusInternalServerError, err, err.Error())
return
}
app.OK(c, resp, "查询成功")
return
}