144 lines
3.2 KiB
Go
144 lines
3.2 KiB
Go
package service
|
|
|
|
import (
|
|
"fonchain-artshow/cmd/dao"
|
|
"fonchain-artshow/cmd/model"
|
|
"fonchain-artshow/pb/test"
|
|
"fonchain-artshow/pkg/serializer"
|
|
"fonchain-artshow/pkg/utils"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
func CreateShowApply(in *test.SaveApplyReq) (err error, applyID uint) {
|
|
showApply := serializer.BuildShowApply(in)
|
|
|
|
tx, err := dao.SaveShowApply(showApply)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
err = tx.Commit().Error
|
|
|
|
// 申请画展包时,暂时不携带画展包信息
|
|
/* showRels := serializer.BuildShowRel(in.Rel, showApply.ID)
|
|
err = dao.SaveShowRels(tx, showRels)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
err = tx.Commit().Error*/
|
|
return err, showApply.ID
|
|
}
|
|
|
|
func UpdateShowApplyWithShowRel(in *test.SaveApplyReq) (err error, applyID uint) {
|
|
|
|
// 更新画展包申请
|
|
showApply := serializer.BuildShowApply(in)
|
|
tx, err := dao.SaveShowApply(showApply)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
// 更新画展包申请关系
|
|
if len(in.Rel) > 0 {
|
|
err, oldShowRelS := dao.QueryShowRelList(showApply.ID) // 查找 旧 show_rel
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return err, showApply.ID
|
|
}
|
|
|
|
newShowRelS := serializer.BuildShowRelM(in.Rel, showApply.ID)
|
|
err, newIds := dao.SaveShowRels(tx, newShowRelS) // 保存 新 show_rel
|
|
|
|
if len(oldShowRelS) > 0 { // 如果 旧 show_rel 有数据 则 删除 旧记录(去除 保留下来的)
|
|
_, del, _ := utils.BeUniqueSlice_uint(serializer.BuildShowRelIDs(oldShowRelS), newIds)
|
|
if len(del) > 0 {
|
|
err = dao.DelShowRel(tx, del)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return err, showApply.ID
|
|
}
|
|
}
|
|
}
|
|
}
|
|
err = tx.Commit().Error
|
|
return err, showApply.ID
|
|
}
|
|
|
|
func UpdateShowApplyStatus(in *test.UpdateApplyStatusReq) (err error) {
|
|
|
|
// 更新画展包申请 状态
|
|
showApply := &model.ShowApply{
|
|
Model: gorm.Model{ID: uint(in.ApplyID)},
|
|
Status: int(in.Status),
|
|
Remark: in.Remark,
|
|
}
|
|
tx, err := dao.SaveShowApply(showApply)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
err = tx.Commit().Error
|
|
return
|
|
}
|
|
|
|
func ShowApplyList(in *test.ApplyListReq) (err error, total int64, out []*test.ApplyDetail) {
|
|
out = make([]*test.ApplyDetail, 0)
|
|
err, total, applyList := dao.ShowApplyList(in)
|
|
if err != nil {
|
|
return
|
|
}
|
|
if len(applyList) > 0 {
|
|
for i := 0; i < len(applyList); i++ {
|
|
showApply := serializer.BuildShowApplyRes(applyList[i])
|
|
out = append(out, showApply)
|
|
}
|
|
}
|
|
return
|
|
}
|
|
|
|
func ShowApplyDetail(applyID uint) (err error, out *test.ApplyShowRes) {
|
|
out = new(test.ApplyShowRes)
|
|
|
|
err, showApply := dao.ShowApplyDetail(applyID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
out.Apply = serializer.BuildShowApplyRes(showApply)
|
|
|
|
err, artShow := dao.ArtShowList_apply(applyID)
|
|
if err != nil {
|
|
return
|
|
}
|
|
out.Show = serializer.BuildArtShowListRes(artShow)
|
|
return
|
|
}
|
|
|
|
func DelApplyByApplyID(in *test.DelApplyReq) (err error) {
|
|
tx, err := dao.DelShowApply(in)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
|
|
for i := 0; i < len(in.ApplyID); i++ {
|
|
err = dao.DelShowRelByApplyID(tx, uint(in.ApplyID[i]))
|
|
if err != nil {
|
|
tx.Rollback()
|
|
return
|
|
}
|
|
}
|
|
err = tx.Commit().Error
|
|
return
|
|
}
|
|
|
|
func QueryShowRel(showID uint) (err error, out *model.ShowRel) {
|
|
out = new(model.ShowRel)
|
|
err, out = dao.QueryShowRel(showID)
|
|
if err != nil {
|
|
return err, nil
|
|
}
|
|
return
|
|
}
|