From d2a43818e9da32608755a62211a30e8e03c93d5d Mon Sep 17 00:00:00 2001 From: louwenzhi Date: Tue, 21 Dec 2021 15:58:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AE=A1=E7=90=86=E5=8F=98?= =?UTF-8?q?=E6=88=90=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/ap/CustDemandVerHead.dao.go | 23 +++- .../implments/CustDemandVerHead.dao.impl.go | 124 +++++++++++++++++- models/ap/CustDemandVerHead.model.go | 17 +++ services/ap/CustDemandVerHead.service.go | 2 +- .../CustDemandVerHead.service.impl.go | 32 +++-- task/createVersion/createVersion.go | 2 +- web/controllers/ap/CustDemandVerHead.rest.go | 13 +- 7 files changed, 190 insertions(+), 23 deletions(-) diff --git a/dao/ap/CustDemandVerHead.dao.go b/dao/ap/CustDemandVerHead.dao.go index 23b5bb4..2c64127 100644 --- a/dao/ap/CustDemandVerHead.dao.go +++ b/dao/ap/CustDemandVerHead.dao.go @@ -186,7 +186,28 @@ type CustDemandVerHeadDAO interface { * @Date : 2021-08-20 11:11:05 * ******************************************************************************/ - SelectData(customerId string, versionId string, artId string, Valid bool) ([]model.CustDemandVerHead, error) + SelectData(*grmi.Paging, string, string, string, bool) (grmi.PagingResult, error) + /****************************************************************************** + * + * @Function Name : SelectDataCount + *----------------------------------------------------------------------------- + * + * @Description : 按条件查询CustDemandVerHead + * + * @Function Parameters : 查询条件 + * + * @Function Parameters : 排序字段 + * + * @Return Value : 查询结果 + * + * @Return Value : 执行时发生的错误 + * + * @Author : 代码生成器创建 + * + * @Date : 2021-08-20 11:11:05 + * + ******************************************************************************/ + SelectDataCount(customerId string, versionId string, artId string, Valid bool) (int64, error) /****************************************************************************** * * @Function Name : SelectUnique diff --git a/dao/ap/implments/CustDemandVerHead.dao.impl.go b/dao/ap/implments/CustDemandVerHead.dao.impl.go index 203e028..ee0eb7d 100644 --- a/dao/ap/implments/CustDemandVerHead.dao.impl.go +++ b/dao/ap/implments/CustDemandVerHead.dao.impl.go @@ -8,6 +8,7 @@ import ( "leit.com/LAPP_CHEERSSON_BACKEND/grmi" meta "leit.com/LAPP_CHEERSSON_BACKEND/meta/ap" model "leit.com/LAPP_CHEERSSON_BACKEND/models/ap" + baseModel "leit.com/LAPP_CHEERSSON_BACKEND/models/base" "xorm.io/core" ) @@ -345,7 +346,7 @@ func (impl *CustDemandVerHeadDAOImplement) IssueVersion(entity *model.CustDemand func (impl *CustDemandVerHeadDAOImplement) IssueGlobalVersion(entity *model.CustDemandVerHead) error { entity.PlantNr = impl.plantNr entity.LastUser = impl.userid - _, err := impl.session.Table(impl.meta.TableName).Cols("GlobalPublish,PublishId,PublishNumber").ID(entity.GetKey()).Update(entity) + _, err := impl.session.Table(impl.meta.TableName).Cols("GlobalPublish,PublishId,PublishNumber").Join("INNER","AP_UserCustlst","AP_UserCustlst.PlantNr = AP_CustDemandVerHead.PlantNr and AP_UserCustlst.CustomerId = AP_CustDemandVerHead.CustomerId").Where("AP_CustDemandVerHead.Status = ? and AP_UserCustlst.UserId = ?",baseModel.STATUS_YES,impl.userid).Update(entity) if err != nil { return grmi.NewDataBaseError(err) } @@ -354,10 +355,127 @@ func (impl *CustDemandVerHeadDAOImplement) IssueGlobalVersion(entity *model.Cust /****************************************************************************** * - * @Reference leit.com/LAPP_CHEERSSON_BACKEND/dao/ap/CustDemandHeadDAO.SelectData + * @Reference leit.com/LAPP_CHEERSSON_BACKEND/dao/ap/CustDemandVerHeadDAO.SelectData * ******************************************************************************/ -func (impl *CustDemandVerHeadDAOImplement) SelectData(customerId string, versionId string, artId string, Valid bool) ([]model.CustDemandVerHead, error) { +func (impl *CustDemandVerHeadDAOImplement) SelectData(paging *grmi.Paging, customerId string, versionId string, artId string, Valid bool) (grmi.PagingResult, error) { + + if Valid { + //查询有效的版本 + + session := impl.session.Table("AP_CustDemandVerHead").Select("AP_CustDemandVerHead.*").Distinct("AP_CustDemandVerHead.VersionId") + session = session.Join("INNER", "AP_CustDemandHead", "AP_CustDemandHead.PlantNr = AP_CustDemandVerHead.PlantNr And AP_CustDemandHead.CustomerId = AP_CustDemandVerHead.CustomerId And AP_CustDemandHead.VersionId = AP_CustDemandVerHead.VersionId") + + session = session.Join("INNER", "AP_UserCustlst", "AP_CustDemandVerHead.PlantNr = AP_UserCustlst.PlantNr And AP_CustDemandVerHead.CustomerId = AP_UserCustlst.CustomerId").Where("AP_CustDemandVerHead.PlantNr = ? and AP_UserCustlst.UserId = ?", impl.plantNr, impl.userid) + if customerId != "" { + session = session.And("AP_CustDemandVerHead.CustomerId = ?", customerId) + } + if versionId != "" { + session = session.And("AP_CustDemandVerHead.VersionId = ?", versionId) + } + if artId != "" { + session = session.Join("INNER", meta.CustDemandVerDetail.TableName, "AP_CustDemandVerHead.PlantNr = AP_CustDemandVerDetail.PlantNr And AP_CustDemandVerHead.CustomerId = AP_CustDemandVerDetail.CustomerId And AP_CustDemandVerHead.VersionId = AP_CustDemandVerDetail.VersionId") + session = session.And("AP_CustDemandVerDetail.ArtId like concat('%%', ?, '%%')", artId) + } + session = session.OrderBy("AP_CustDemandVerHead.VersionId") + + data := make([]model.CustDemandVerHead, 0, 10) + + err := session.Limit(int(paging.Size), int(paging.Offset())).Find(&data) + if err != nil { + return grmi.EmptyPagingResult, grmi.NewDataBaseError(err) + } + return grmi.PagingResult{Records: data, Count: paging.Size, PageNumber: paging.Number, PageSize: paging.Size}, nil + } else { + + session := impl.session.Table(impl.meta.TableName).Select("AP_CustDemandVerHead.*").Distinct("AP_CustDemandVerHead.VersionId") + + session = session.Join("INNER", "AP_UserCustlst", "AP_CustDemandVerHead.PlantNr = AP_UserCustlst.PlantNr And AP_CustDemandVerHead.CustomerId = AP_UserCustlst.CustomerId").Where("AP_CustDemandVerHead.PlantNr = ? and AP_UserCustlst.UserId = ?", impl.plantNr, impl.userid) + if customerId != "" { + session = session.And("AP_CustDemandVerHead.CustomerId = ?", customerId) + } + if versionId != "" { + session = session.And("AP_CustDemandVerHead.VersionId = ?", versionId) + } + if artId != "" { + session = session.Join("INNER", meta.CustDemandVerDetail.TableName, "AP_CustDemandVerHead.PlantNr = AP_CustDemandVerDetail.PlantNr And AP_CustDemandVerHead.CustomerId = AP_CustDemandVerDetail.CustomerId And AP_CustDemandVerHead.VersionId = AP_CustDemandVerDetail.VersionId") + session = session.And("AP_CustDemandVerDetail.ArtId like concat('%%', ?, '%%')", artId) + } + session = session.OrderBy("AP_CustDemandVerHead.VersionId") + + data := make([]model.CustDemandVerHead, 0, 10) + + err := session.Limit(int(paging.Size), int(paging.Offset())).Find(&data) + if err != nil { + return grmi.EmptyPagingResult, grmi.NewDataBaseError(err) + } + + return grmi.PagingResult{Records: data, Count: paging.Size, PageNumber: paging.Number, PageSize: paging.Size}, nil + } +} + +/****************************************************************************** + * + * @Reference leit.com/LAPP_CHEERSSON_BACKEND/dao/ap/CustDemandVerHeadDAO.SelectData + * + ******************************************************************************/ +func (impl *CustDemandVerHeadDAOImplement) SelectDataCount(customerId string, versionId string, artId string, Valid bool) (int64, error) { + + if Valid { + //查询有效的版本 + + session := impl.session.Table("AP_CustDemandVerHead").Select("count(AP_CustDemandVerHead.VersionId) as countNum") + session = session.Join("INNER", "AP_CustDemandHead", "AP_CustDemandHead.PlantNr = AP_CustDemandVerHead.PlantNr And AP_CustDemandHead.CustomerId = AP_CustDemandVerHead.CustomerId And AP_CustDemandHead.VersionId = AP_CustDemandVerHead.VersionId") + + session = session.Join("INNER", "AP_UserCustlst", "AP_CustDemandVerHead.PlantNr = AP_UserCustlst.PlantNr And AP_CustDemandVerHead.CustomerId = AP_UserCustlst.CustomerId").Where("AP_CustDemandVerHead.PlantNr = ? and AP_UserCustlst.UserId = ?", impl.plantNr, impl.userid) + if customerId != "" { + session = session.And("AP_CustDemandVerHead.CustomerId = ?", customerId) + } + if versionId != "" { + session = session.And("AP_CustDemandVerHead.VersionId = ?", versionId) + } + if artId != "" { + session = session.Join("INNER", meta.CustDemandVerDetail.TableName, "AP_CustDemandVerHead.PlantNr = AP_CustDemandVerDetail.PlantNr And AP_CustDemandVerHead.CustomerId = AP_CustDemandVerDetail.CustomerId And AP_CustDemandVerHead.VersionId = AP_CustDemandVerDetail.VersionId") + session = session.And("AP_CustDemandVerDetail.ArtId like concat('%%', ?, '%%')", artId) + } + + data := new(model.CustomerCount) + count,err := session.Count(data) + if err != nil { + return 0, grmi.NewDataBaseError(err) + } + return count, nil + } else { + + session := impl.session.Table(impl.meta.TableName).Select("count(AP_CustDemandVerHead.VersionId) as countNum") + + session = session.Join("INNER", "AP_UserCustlst", "AP_CustDemandVerHead.PlantNr = AP_UserCustlst.PlantNr And AP_CustDemandVerHead.CustomerId = AP_UserCustlst.CustomerId").Where("AP_CustDemandVerHead.PlantNr = ? and AP_UserCustlst.UserId = ?", impl.plantNr, impl.userid) + if customerId != "" { + session = session.And("AP_CustDemandVerHead.CustomerId = ?", customerId) + } + if versionId != "" { + session = session.And("AP_CustDemandVerHead.VersionId = ?", versionId) + } + if artId != "" { + session = session.Join("INNER", meta.CustDemandVerDetail.TableName, "AP_CustDemandVerHead.PlantNr = AP_CustDemandVerDetail.PlantNr And AP_CustDemandVerHead.CustomerId = AP_CustDemandVerDetail.CustomerId And AP_CustDemandVerHead.VersionId = AP_CustDemandVerDetail.VersionId") + session = session.And("AP_CustDemandVerDetail.ArtId like concat('%%', ?, '%%')", artId) + } + + data := new(model.CustomerCount) + count,err := session.Count(data) + if err != nil { + return 0, grmi.NewDataBaseError(err) + } + return count, nil + } +} + +/****************************************************************************** + * + * @Reference leit.com/LAPP_CHEERSSON_BACKEND/dao/ap/CustDemandHeadDAO.SelectDataTest + * + ******************************************************************************/ +func (impl *CustDemandVerHeadDAOImplement) SelectDataTest(customerId string, versionId string, artId string, Valid bool) ([]model.CustDemandVerHead, error) { if Valid { session := impl.session.Table("AP_CustDemandVerHead").Select("AP_CustDemandVerHead.*").Distinct("AP_CustDemandVerHead.VersionId") diff --git a/models/ap/CustDemandVerHead.model.go b/models/ap/CustDemandVerHead.model.go index 57ae5e1..ee54efb 100644 --- a/models/ap/CustDemandVerHead.model.go +++ b/models/ap/CustDemandVerHead.model.go @@ -90,3 +90,20 @@ type CustomerItem struct { SortKeys []string `json:"SortKeys" xorm:"-"` CustDemandVerDetail map[string]CustDemandVerDetail `json:"CustDemandVerDetail" xorm:"-"` } + +/****************************************************************************** + * + * @Struct Name : CustomerItem + *----------------------------------------------------------------------------- + * + * @Description : 数据项 + * + * @Author : 娄文智 + * + * @Date : 2021-09-08 + * + ******************************************************************************/ + +type CustomerCount struct { + CountNum int64 `json:"countNum" xorm:"-"` +} \ No newline at end of file diff --git a/services/ap/CustDemandVerHead.service.go b/services/ap/CustDemandVerHead.service.go index 97ad2b8..d346016 100644 --- a/services/ap/CustDemandVerHead.service.go +++ b/services/ap/CustDemandVerHead.service.go @@ -492,7 +492,7 @@ type CustDemandVerHeadService interface { * @Date : 2021-08-20 11:11:05 * ******************************************************************************/ - SelectData(*global.User, string, string,string,bool) ([]model.CustDemandVerHead, error) + SelectData(*global.User,map[string]string, string, string,string,bool) (grmi.PagingResult, error) /****************************************************************************** * * @Function Name : SelectData diff --git a/services/ap/implments/CustDemandVerHead.service.impl.go b/services/ap/implments/CustDemandVerHead.service.impl.go index ce70258..3364d63 100644 --- a/services/ap/implments/CustDemandVerHead.service.impl.go +++ b/services/ap/implments/CustDemandVerHead.service.impl.go @@ -746,42 +746,52 @@ func (impl *CustDemandVerHeadServiceImplement) Select(user *global.User, urlPara * @Reference leit.com/LAPP_CHEERSSON_BACKEND/services/ap/CustDemandVerHeadService.SelectData * ******************************************************************************/ -func (impl *CustDemandVerHeadServiceImplement) SelectData(user *global.User, customerId string, versionId string, artId string, Valid bool) ([]model.CustDemandVerHead, error) { +func (impl *CustDemandVerHeadServiceImplement) SelectData(user *global.User, urlParameters map[string]string, customerId string, versionId string, artId string, Valid bool) (grmi.PagingResult, error) { grmi.Log(user, "/services/ap/implments/CustDemandVerHead.service.impl.go", "SelectCustDemandVerHead", "查询CustDemandVerHead") engine := db.Eloquent.Master() session := engine.NewSession() defer session.Close() - engine.ShowSQL(true) dao := dal.NewCustDemandVerHeadDAO(session, user.PlantNr, user.UserId) globalDao := dal.NewCustDemandHeadDAO(session, user.PlantNr, user.UserId) - result, err := dao.SelectData(customerId, versionId, artId, Valid) + + condition := DefaultConditionOfCustDemandVerHeadAndPaging + condition.Fill(urlParameters) + + result, err := dao.SelectData(condition.Paging, customerId, versionId, artId, Valid) if err != nil { - return nil, err + return grmi.EmptyPagingResult, err + } + result.Count,err = dao.SelectDataCount(customerId, versionId, artId, Valid) + if err != nil { + return grmi.EmptyPagingResult, err } - list, err := globalDao.Select([]grmi.Predicate{ meta.CustDemandHead_CustomerId.NewPredicate(grmi.Equal, customerId), }, nil) if err != nil { - return nil, err + return grmi.EmptyPagingResult, err } if len(list) > 0 { var versionId string for _, v := range list { versionId = v.VersionId } - for k, v := range result { - if versionId == v.VersionId { - result[k].Valid = true - } + resultInfo,ok := result.Records.([]model.CustDemandVerHead) + if ok{ + for k, v := range resultInfo { + if versionId == v.VersionId { + resultInfo[k].Valid = true + } + } + result.Records = resultInfo } + } return result, nil } - /****************************************************************************** * * @Reference leit.com/LAPP_CHEERSSON_BACKEND/services/ap/CustDemandVerHeadService.SelectUnique diff --git a/task/createVersion/createVersion.go b/task/createVersion/createVersion.go index a749674..bd4a555 100644 --- a/task/createVersion/createVersion.go +++ b/task/createVersion/createVersion.go @@ -57,7 +57,7 @@ func doTaskVersion(ctx context.Context) { user.UserId = "auto" err := serviceOfCustVerHead.SelectOneByCustTask(user, task) if err != nil { - glog.InfoExtln("创建错误记录","err:",err) + glog.InfoExtln("创建错误记录", "err:", err) continue } } diff --git a/web/controllers/ap/CustDemandVerHead.rest.go b/web/controllers/ap/CustDemandVerHead.rest.go index f8bfda0..8c94d59 100644 --- a/web/controllers/ap/CustDemandVerHead.rest.go +++ b/web/controllers/ap/CustDemandVerHead.rest.go @@ -1342,7 +1342,7 @@ func RegisterRemoveIssueOneCustDemandVerHead(party router.Party, httpMethod stri * @Date : 2021-08-20 11:11:05 * ******************************************************************************/ -func RegisterSearchCustDemandVerHead(party router.Party, path string, method func(*global.User, string, string, string, bool) ([]model.CustDemandVerHead, error)) { +func RegisterSearchCustDemandVerHead(party router.Party, path string, method func(*global.User, map[string]string, string, string, string, bool) (grmi.PagingResult, error)) { party.Get(path, func(ctx iris.Context) { user, ok := jwts.ParseToken(ctx) @@ -1354,15 +1354,16 @@ func RegisterSearchCustDemandVerHead(party router.Party, path string, method fun artId := ctx.URLParam("artId") versionId := ctx.URLParam("versionId") valid, _ := ctx.URLParamBool("valid") - result, err := method(user, customerId, versionId, artId, valid) + + urlParameters := make(map[string]string) + urlParameters["pageNumber"] = ctx.URLParam("pageNumber") + urlParameters["pageSize"] = ctx.URLParam("pageSize") + + result, err := method(user, urlParameters, customerId, versionId, artId, valid) if err != nil { supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) return } - if result == nil { - supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil) - return - } supports.Ok(ctx, supports.OptionSuccess, result) }) }