Browse Source

开启workcalendarLst批量插入的接口功能

pull/111/head
zhangxin 3 years ago
parent
commit
0828a5e52b
4 changed files with 68 additions and 14 deletions
  1. +1
    -1
      services/base/WorkCalendarLst.service.go
  2. +3
    -0
      services/base/implments/WorkCalendar.service.impl.go
  3. +18
    -11
      services/base/implments/WorkCalendarLst.service.impl.go
  4. +46
    -2
      web/controllers/base/WorkCalendarLst.rest.go

+ 1
- 1
services/base/WorkCalendarLst.service.go View File

@ -117,7 +117,7 @@ type WorkCalendarLstService interface {
* @Date : 2021-03-18 23:20:31
*
******************************************************************************/
Insert(*models.Usertab, *[]model.WorkCalendarLst) error
Insert(*models.Usertab, *model.WorkCalendarLstInsertReq) error
/******************************************************************************
*
* @Function Name : Delete


+ 3
- 0
services/base/implments/WorkCalendar.service.impl.go View File

@ -161,6 +161,9 @@ func (impl *WorkCalendarServiceImplement) SelectOne(user *models.Usertab, workCa
if err != nil {
return nil, err
}
if result == nil {
return nil, grmi.NewBusinessError("不存在该条日历,请检查")
}
workCalendarLstDao := dal.NewWorkCalendarLstDAO(session, user.Pid, user.Userid)
li, err := workCalendarLstDao.SelectJoinDayModel(workCalendarNr)
if err != nil {


+ 18
- 11
services/base/implments/WorkCalendarLst.service.impl.go View File

@ -212,29 +212,36 @@ func (impl *WorkCalendarLstServiceImplement) UpdateOne(user *models.Usertab, ent
* @Reference LAPP_GAAS_GFrame_BACKEND/services/base/WorkCalendarLstService.Insert
*
******************************************************************************/
func (impl *WorkCalendarLstServiceImplement) Insert(user *models.Usertab, entities *[]model.WorkCalendarLst) error {
func (impl *WorkCalendarLstServiceImplement) Insert(user *models.Usertab, entities *model.WorkCalendarLstInsertReq) error {
grmi.Log(user, "/services/base/implments/WorkCalendarLst.service.impl.go", "InsertWorkCalendarLst", "插入多个WorkCalendarLst")
engine := db.Eloquent.Master()
session := engine.NewSession()
defer session.Close()
err := session.Begin()
if err != nil {
return err
}
dao := dal.NewWorkCalendarLstDAO(session, user.Pid, user.Userid)
for _, entity := range *entities {
record, err := dao.SelectOne(entity.WorkCalendarNr, entity.WorkDate)
if err != nil {
return err
}
if record != nil {
return grmi.NewBusinessError("已经存在相同主键的记录!")
workCalendarNr := entities.WorkCalendarNr
workCalendarLstLi := entities.Records
for _, entity := range workCalendarLstLi {
if workCalendarNr != entity.WorkCalendarNr {
return grmi.NewBusinessError("与设置的workCalendarNr不一致,请检查")
}
}
err := dao.Insert(entities)
err = dao.DeleteWhere([]grmi.Predicate{meta.WorkCalendarLst_WorkCalendarNr.NewPredicate(grmi.Equal, workCalendarNr)})
if err != nil {
session.Rollback()
return err
}
err = dao.Insert(&workCalendarLstLi)
if err != nil {
session.Rollback()
return err
}
session.Commit()
return nil
}


+ 46
- 2
web/controllers/base/WorkCalendarLst.rest.go View File

@ -294,9 +294,9 @@ func RegisterMultiWorkCalendarLst(party router.Party, httpMethod string, path st
* @Date : 2021-03-18 22:49:12
*
******************************************************************************/
func RegisterInsertWorkCalendarLst(party router.Party, path string, method func(*models.Usertab, *[]model.WorkCalendarLst) error) {
func RegisterInsertWorkCalendarLst(party router.Party, path string, method func(*models.Usertab, *model.WorkCalendarLstInsertReq) error) {
RegisterMultiWorkCalendarLst(party, "POST", path, method)
RegisterMultiInsertWorkCalendarLst(party, "POST", path, method)
}
/******************************************************************************
@ -380,3 +380,47 @@ func RegisterUpdateWorkCalendarLst(party router.Party, path string, method func(
RegisterMultiWorkCalendarLst(party, "PUT", path, method)
}
/******************************************************************************
*
* @Function Name : RegisterMultiInsertWorkCalendarLst
*-----------------------------------------------------------------------------
*
* @Description : 为一个处理插入多条WorkCalendarLst的方法注册路由
*
* @Function Parameters : 路由分组
*
* @Function Parameters : HTTP方法
*
* @Function Parameters : 路径
*
* @Function Parameters : 实际处理请求的方法
*
* @Author : 张鑫
*
* @Date : 2021-04-15
*
******************************************************************************/
func RegisterMultiInsertWorkCalendarLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *model.WorkCalendarLstInsertReq) error) {
party.Handle(httpMethod, path, func(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
var entities model.WorkCalendarLstInsertReq
err := ctx.ReadJSON(&entities)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
err = method(user, &entities)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, nil)
})
}

Loading…
Cancel
Save