From 43ebc2a6581dc5d714f232587a7148b29c6d8103 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 15 Apr 2021 14:46:05 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0WorkCalendarNr=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E4=B8=BA=E8=87=AA=E5=A2=9E=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/base/WorkCalendar.model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/base/WorkCalendar.model.go b/models/base/WorkCalendar.model.go index 31849de..c80bdba 100644 --- a/models/base/WorkCalendar.model.go +++ b/models/base/WorkCalendar.model.go @@ -21,7 +21,7 @@ import ( ******************************************************************************/ type WorkCalendar struct { PlantNr int `xorm:"pk int 'PlantNr'" json:"WorkCalendar-PlantNr"` - WorkCalendarNr int `xorm:"pk int 'WorkCalendarNr'" json:"WorkCalendar-WorkCalendarNr"` + WorkCalendarNr int `xorm:"pk int 'WorkCalendarNr' autoincr" json:"WorkCalendar-WorkCalendarNr"` Descr string `xorm:"nvarchar(100) 'Descr' not null" json:"WorkCalendar-Descr"` LastModify grmi.DateTime `xorm:"datetime 'LastModify' not null updated" json:"WorkCalendar-LastModify"` LastUser string `xorm:"nvarchar(20) 'LastUser' not null" json:"WorkCalendar-LastUser"` From 0c9e305c278c8d9360877e97dbe95db426540a34 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 15 Apr 2021 14:46:15 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=BC=80=E5=90=AF=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/base/base.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/models/base/base.go b/models/base/base.go index fb6c3eb..05ffaac 100644 --- a/models/base/base.go +++ b/models/base/base.go @@ -1,6 +1,5 @@ package base - /****************************************************************************** * * @Struct Name : WeekModelLstInsertReq @@ -17,3 +16,20 @@ type WeekModelLstInsertReq struct { WeekModelNr int `json:"weekModelNr"` Records []WeekModelLst `json:"records"` } + +/****************************************************************************** + * + * @Struct Name : WorkCalendarLstInsertReq + *----------------------------------------------------------------------------- + * + * @Description : WorkCalendarLstInsertReq workCalendarLst 批量插入请求体映射 + * + * @Author : 张鑫 + * + * @Date : 2021-04-15 + * + ******************************************************************************/ +type WorkCalendarLstInsertReq struct { + WorkCalendarNr int `json:"workCalendarNr"` + Records []WorkCalendarLst `json:"records"` +} From 0828a5e52b69e21263014ceb5b66a6afad4f1d23 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 15 Apr 2021 14:47:06 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=BC=80=E5=90=AFworkcalendarLst=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E6=8F=92=E5=85=A5=E7=9A=84=E6=8E=A5=E5=8F=A3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/base/WorkCalendarLst.service.go | 2 +- .../implments/WorkCalendar.service.impl.go | 3 ++ .../implments/WorkCalendarLst.service.impl.go | 29 ++++++----- web/controllers/base/WorkCalendarLst.rest.go | 48 ++++++++++++++++++- 4 files changed, 68 insertions(+), 14 deletions(-) diff --git a/services/base/WorkCalendarLst.service.go b/services/base/WorkCalendarLst.service.go index 6f0c8c4..c85334c 100644 --- a/services/base/WorkCalendarLst.service.go +++ b/services/base/WorkCalendarLst.service.go @@ -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 diff --git a/services/base/implments/WorkCalendar.service.impl.go b/services/base/implments/WorkCalendar.service.impl.go index 9dc1c47..a81bd12 100644 --- a/services/base/implments/WorkCalendar.service.impl.go +++ b/services/base/implments/WorkCalendar.service.impl.go @@ -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 { diff --git a/services/base/implments/WorkCalendarLst.service.impl.go b/services/base/implments/WorkCalendarLst.service.impl.go index de00de0..e2247b5 100644 --- a/services/base/implments/WorkCalendarLst.service.impl.go +++ b/services/base/implments/WorkCalendarLst.service.impl.go @@ -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 } diff --git a/web/controllers/base/WorkCalendarLst.rest.go b/web/controllers/base/WorkCalendarLst.rest.go index 85f365b..e2ecd37 100644 --- a/web/controllers/base/WorkCalendarLst.rest.go +++ b/web/controllers/base/WorkCalendarLst.rest.go @@ -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) + }) +} \ No newline at end of file From d41e1f0450075dfcc7abe55bd9747388b29b601b Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 15 Apr 2021 14:47:19 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=BC=80=E5=90=AF=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/base/base.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/web/controllers/base/base.go b/web/controllers/base/base.go index 29f155b..499f053 100644 --- a/web/controllers/base/base.go +++ b/web/controllers/base/base.go @@ -660,19 +660,19 @@ func RegisterRoutes() { // WorkCalendarLst的服务实例 var serviceOfWorkCalendarLst = svr.NewWorkCalendarLstService() // WorkCalendarLst插入一条 - RegisterInsertOneWorkCalendarLst(workcalendarlst, "/insertone", serviceOfWorkCalendarLst.InsertOne) + //RegisterInsertOneWorkCalendarLst(workcalendarlst, "/insertone", serviceOfWorkCalendarLst.InsertOne) // WorkCalendarLst插入多条 - // RegisterInsertWorkCalendarLst(workcalendarlst, "/insert", serviceOfWorkCalendarLst.Insert) + RegisterInsertWorkCalendarLst(workcalendarlst, "/insert", serviceOfWorkCalendarLst.Insert) // WorkCalendarLst删除一条 - RegisterDeleteOneWorkCalendarLst(workcalendarlst, "/deleteone", serviceOfWorkCalendarLst.DeleteOne) + //RegisterDeleteOneWorkCalendarLst(workcalendarlst, "/deleteone", serviceOfWorkCalendarLst.DeleteOne) // WorkCalendarLst删除多条 // RegisterDeleteWorkCalendarLst(workcalendarlst, "/delete", serviceOfWorkCalendarLst.Delete) // WorkCalendarLst查询多条 - RegisterSelectWorkCalendarLst(workcalendarlst, "/query", serviceOfWorkCalendarLst.Select) + //RegisterSelectWorkCalendarLst(workcalendarlst, "/query", serviceOfWorkCalendarLst.Select) // WorkCalendarLst查询一条 - RegisterSelectOneWorkCalendarLst(workcalendarlst, "/get", serviceOfWorkCalendarLst.SelectOne) + //RegisterSelectOneWorkCalendarLst(workcalendarlst, "/get", serviceOfWorkCalendarLst.SelectOne) // WorkCalendarLst修改一条 - RegisterUpdateOneWorkCalendarLst(workcalendarlst, "/updateone", serviceOfWorkCalendarLst.UpdateOne) + //RegisterUpdateOneWorkCalendarLst(workcalendarlst, "/updateone", serviceOfWorkCalendarLst.UpdateOne) // WorkCalendarLst修改多条 // RegisterUpdateWorkCalendarLst(workcalendarlst, "/update", serviceOfWorkCalendarLst.Update)