174 lines
4.7 KiB
Go
174 lines
4.7 KiB
Go
|
package launch
|
||
|
|
||
|
import (
|
||
|
"errors"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/api/account"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/api/conference"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/api/documentContract"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/e"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/model/login"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/request"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/service"
|
||
|
"github.com/fonchain_enterprise/fonchain-main/pkg/utils/launch"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/gin-gonic/gin/binding"
|
||
|
)
|
||
|
|
||
|
func CreateContract(c *gin.Context) {
|
||
|
req := &documentContract.CreateContractRequest{}
|
||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
userInfoAny, _ := c.Get("jwtInfo")
|
||
|
userInfo := userInfoAny.(login.Info)
|
||
|
infoReq := &account.InfoRequest{
|
||
|
ID: userInfo.ID,
|
||
|
}
|
||
|
infoRes, err := service.AccountProvider.Info(c, infoReq)
|
||
|
req.CreatedUid = infoRes.Info.ID
|
||
|
req.JobNum = infoRes.Info.JobNum
|
||
|
req.Creator = infoRes.Info.NickName
|
||
|
res, err := service.GrpcDocumentContractImpl.CreateContract(c, req)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.Error, err)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
service.Success(c, res)
|
||
|
return
|
||
|
}
|
||
|
func UpdateContract(c *gin.Context) {
|
||
|
req := &documentContract.UpdateContractRequest{}
|
||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
res, err := service.GrpcDocumentContractImpl.UpdateContract(c, req)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.Error, err)
|
||
|
return
|
||
|
}
|
||
|
service.Success(c, res)
|
||
|
return
|
||
|
}
|
||
|
func DeletedContract(c *gin.Context) {
|
||
|
req := &documentContract.DeletedContractRequest{}
|
||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
res, err := service.GrpcDocumentContractImpl.DeletedContract(c, req)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.Error, err)
|
||
|
return
|
||
|
}
|
||
|
service.Success(c, res)
|
||
|
return
|
||
|
}
|
||
|
func FindContract(c *gin.Context) {
|
||
|
req := &documentContract.FindContractRequest{}
|
||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
res, err := service.GrpcDocumentContractImpl.FindContract(c, req)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.Error, err)
|
||
|
return
|
||
|
}
|
||
|
service.Success(c, res)
|
||
|
return
|
||
|
}
|
||
|
func CreateSort(c *gin.Context) {
|
||
|
req := &documentContract.SortCreateRequest{}
|
||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
res, err := service.GrpcDocumentContractImpl.CreateSort(c, req)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.Error, err)
|
||
|
return
|
||
|
}
|
||
|
service.Success(c, res)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func FindSort(c *gin.Context) {
|
||
|
req := &documentContract.SortFindRequest{}
|
||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
res, err := service.GrpcDocumentContractImpl.FindSort(c, req)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.Error, err)
|
||
|
return
|
||
|
}
|
||
|
service.Success(c, res)
|
||
|
return
|
||
|
}
|
||
|
func DownloadPackaged(c *gin.Context) {
|
||
|
var reqData request.Response
|
||
|
var fileType string
|
||
|
req := &request.DownloadPackaged{}
|
||
|
if err := c.ShouldBindBodyWith(&req, binding.JSON); err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
if req.Type == "conference" {
|
||
|
conferenceReq := &conference.FindConferenceRequest{
|
||
|
Ids: req.Ids,
|
||
|
}
|
||
|
res, err := service.GrpcConferenceImpl.FindConference(c, conferenceReq)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
fileType = "会议录"
|
||
|
for _, i := range res.Conference {
|
||
|
var attachments []request.Attachment
|
||
|
for _, att := range i.Attachment {
|
||
|
attachments = append(attachments, request.Attachment{
|
||
|
URL: att.Url,
|
||
|
Name: att.Name,
|
||
|
})
|
||
|
}
|
||
|
reqData.Contracts = append(reqData.Contracts, request.Contract{
|
||
|
Theme: i.Theme,
|
||
|
Attachment: attachments,
|
||
|
})
|
||
|
}
|
||
|
} else if req.Type == "contract" {
|
||
|
contractReq := &documentContract.FindContractRequest{
|
||
|
Ids: req.Ids,
|
||
|
}
|
||
|
res, err := service.GrpcDocumentContractImpl.FindContract(c, contractReq)
|
||
|
if err != nil {
|
||
|
service.Error(c, e.InvalidParams, err)
|
||
|
return
|
||
|
}
|
||
|
fileType = "合同"
|
||
|
for _, i := range res.Contract {
|
||
|
var attachments []request.Attachment
|
||
|
for _, att := range i.Attachment {
|
||
|
attachments = append(attachments, request.Attachment{
|
||
|
URL: att.Url,
|
||
|
Name: att.Name,
|
||
|
})
|
||
|
}
|
||
|
reqData.Contracts = append(reqData.Contracts, request.Contract{
|
||
|
Theme: i.Theme,
|
||
|
Attachment: attachments,
|
||
|
})
|
||
|
}
|
||
|
} else {
|
||
|
service.Error(c, e.InvalidParams, errors.New(e.GetMsg(e.InvalidParams)))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
launch.DownloadAndZip(reqData, fileType, c.Writer)
|
||
|
|
||
|
}
|