From aeaafabca24bb7011eb0b41616d2084d7d0c6123 Mon Sep 17 00:00:00 2001 From: "DESKTOP-IO8B2ND\\ZhangXin" Date: Thu, 27 Oct 2022 16:31:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=BC=E5=87=BA=E5=8F=91?= =?UTF-8?q?=E8=BF=90=E6=A0=A1=E9=AA=8C=E6=95=B0=E6=8D=AE=E7=9A=84=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=92=8C=E5=AF=BC=E5=87=BA=E9=A1=BA=E5=BC=95=E5=85=A8?= =?UTF-8?q?=E9=87=8F=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/pln/ToyotaCalloff.dao.go | 2 + dao/pln/implments/ToyotaCalloff.dao.impl.go | 34 +++++++++ grmi/export.go | 72 +++++++++++++++++++ services/pln/ToyotaCalloff.service.go | 2 + .../pln/implments/ToyotaCallOffCheck.impl.go | 51 ++++++------- .../implments/ToyotaCalloff.service.impl.go | 52 ++++++-------- web/controllers/pln/ToyotaCalloff.rest.go | 18 +++++ web/controllers/pln/pln.go | 2 + 8 files changed, 174 insertions(+), 59 deletions(-) diff --git a/dao/pln/ToyotaCalloff.dao.go b/dao/pln/ToyotaCalloff.dao.go index cc85c92..f88fb10 100644 --- a/dao/pln/ToyotaCalloff.dao.go +++ b/dao/pln/ToyotaCalloff.dao.go @@ -262,6 +262,8 @@ type ToyotaCalloffDAO interface { SelectTopOne(predicates []grmi.Predicate, orderByFields []grmi.Field) (*model.ToyotaCalloff, error) // SelectAndPagingCheck 发运校验分页查询 SelectAndPagingCheck(paging *grmi.Paging, predicates []grmi.Predicate, orderByFields []grmi.Field) (grmi.PagingResult, error) + // SelectWithoutPaging 不分页查询 + SelectWithoutPaging(paging *grmi.Paging, predicates []grmi.Predicate, orderByFields []grmi.Field) ([]model.ToyotaCalloff, error) } /****************************************************************************** diff --git a/dao/pln/implments/ToyotaCalloff.dao.impl.go b/dao/pln/implments/ToyotaCalloff.dao.impl.go index 752bcce..42aaf0f 100644 --- a/dao/pln/implments/ToyotaCalloff.dao.impl.go +++ b/dao/pln/implments/ToyotaCalloff.dao.impl.go @@ -500,3 +500,37 @@ func (impl *ToyotaCalloffDAOImplement) SelectAndPagingCheck(paging *grmi.Paging, } return grmi.PagingResult{Records: data, Count: count, PageNumber: paging.Number, PageSize: paging.Size}, nil } + + +/****************************************************************************** + * + * @Reference LAPP_ACURA_MOM_BACKEND/dao/pln/ToyotaCalloffDAO.SelectAndPaging + * + ******************************************************************************/ +func (impl *ToyotaCalloffDAOImplement) SelectWithoutPaging(paging *grmi.Paging, predicates []grmi.Predicate, orderByFields []grmi.Field) ([]model.ToyotaCalloff, error) { + + parameters := []interface{}{impl.plantNr} + where := fmt.Sprintf("%s = ?", meta.ToyotaCalloff_PlantNr.ColumnName) + + if predicates != nil { + for _, predicate := range predicates { + if predicate.ColumnName == meta.ToyotaCalloff_Parsed.ColumnName { + if len(predicate.Values) != 0 { + parsed := predicate.Values[0] + if parsed == int64(-1) { + where += fmt.Sprintf(" and %s != ?", meta.ToyotaCalloff_Parsed.ColumnName) + parameters = append(parameters, model.CALLOFF_STATUS_SHIPED) + continue + } + } + } + where += predicate.Build() + parameters = append(parameters, predicate.Values...) + } + } + orderBy := " order by " + meta.ToyotaCalloff_RecordId.SortColumnName + " desc " + data := make([]model.ToyotaCalloff, 0, 10) + where = " where " + where + err := impl.session.Table(impl.meta.TableName).SQL("select * from ["+impl.meta.TableName+"]"+where+orderBy, parameters...).Find(&data) + return data, err +} \ No newline at end of file diff --git a/grmi/export.go b/grmi/export.go index 03a6e1d..dda652e 100644 --- a/grmi/export.go +++ b/grmi/export.go @@ -102,3 +102,75 @@ func SaveExcelFile(list []interface{}, titleList []string, sheetName string, pre } return pathLi[1], nil } + +func SaveExcelFileUseMap(list []map[string]interface{}, titleList []string, sheetName string, prefixFilename string) (filepath string, err error) { + file := excelize.NewFile() + if sheetName != "Sheet1" { + file.NewSheet(sheetName) + file.DeleteSheet("Sheet1") + } + streamWriter, err := file.NewStreamWriter(sheetName) + if err != nil { + return "", err + } + for index, item := range list { + if index == 0 { + row := make([]interface{}, len(titleList)) + for i := 0; i < len(titleList); i++ { + row[i] = titleList[i] + } + cell, _ := excelize.CoordinatesToCellName(1, 1) + if err := streamWriter.SetRow(cell, row); err != nil { + return "", err + } + } + row := make([]interface{}, len(titleList)) + for i, title := range titleList { + value, exist := item[title] + if !exist { + row[i] = "" + continue + } + date, ok := value.(Date) + if ok { + row[i] = date.ToString() + if row[i] == "1900-01-01" { + row[i] = "" + } + continue + } + datetime, ok := value.(DateTime) + if ok { + row[i] = datetime.ToString() + if row[i] == "1900-01-01 00:00:00" { + row[i] = "" + } + continue + } + row[i] = value + } + cell, _ := excelize.CoordinatesToCellName(1, index+2) + if err := streamWriter.SetRow(cell, row); err != nil { + return "", err + } + } + if err := streamWriter.Flush(); err != nil { + return "", err + } + filename := utils.MakeOrderSn(prefixFilename) + ".xlsx" + dirname, err := utils.GetCurrentPath("web/public/uploadxlsx") + if err != nil { + return "", err + } + filepath = dirname + "/" + filename + err = file.SaveAs(filepath) + if err != nil { + return "", err + } + pathLi := strings.Split(filepath, "web\\") + if len(pathLi) != 2 { + return "", errors.New("导出失败,请重试") + } + return pathLi[1], nil +} + diff --git a/services/pln/ToyotaCalloff.service.go b/services/pln/ToyotaCalloff.service.go index 810b935..4b1c22b 100644 --- a/services/pln/ToyotaCalloff.service.go +++ b/services/pln/ToyotaCalloff.service.go @@ -240,6 +240,8 @@ type ToyotaCalloffService interface { Check(user *global.User, barcode string) error // SelectAndPagingCheck 发运校验的分页 SelectAndPagingCheck(user *global.User, urlParameters map[string]string) (grmi.PagingResult, error) + // ExportPageDataCheck 发运校验导出页面数据 + ExportPageDataCheck(user *global.User, urlParameters map[string]string) (filepath string, err error) } /****************************************************************************** diff --git a/services/pln/implments/ToyotaCallOffCheck.impl.go b/services/pln/implments/ToyotaCallOffCheck.impl.go index 4962299..11988b6 100644 --- a/services/pln/implments/ToyotaCallOffCheck.impl.go +++ b/services/pln/implments/ToyotaCallOffCheck.impl.go @@ -359,13 +359,12 @@ func (impl *ToyotaCalloffServiceImplement) ExportPageDataCheck(user *global.User predicates = append(predicates, p) dao := dal.NewToyotaCalloffDAO(session, user.PlantNr, user.UserId) condition.Fill(urlParameters) - result, err := dao.SelectAndPaging(condition.Paging, predicates, []grmi.Field{meta.ToyotaCalloff_RecordId}) + result, err := dao.SelectWithoutPaging(condition.Paging, predicates, []grmi.Field{meta.ToyotaCalloff_RecordId}) if err != nil { return "", err } - data := result.Records.([]model.ToyotaCalloff) tabNameLi, err := tolnameDao.OriginSelect([]grmi.Predicate{ - baseMeta.TabColName_TabName.NewPredicate(grmi.Equal, "ToyotaCalloff"), + baseMeta.TabColName_TabName.NewPredicate(grmi.Equal, "PLN_ToyotaCalloff"), }, nil) if err != nil { return "", grmi.NewBusinessError("查询翻译数据失败, 错误:" + err.Error()) @@ -385,37 +384,31 @@ func (impl *ToyotaCalloffServiceImplement) ExportPageDataCheck(user *global.User for _, item := range stdefLi { stdefMap[item.StdefTyp] = item.Bez } - li := make([]interface{}, 0, len(data)) - for _, item := range data { - parsed, exist := stdefMap[strconv.Itoa(item.Parsed)] - if !exist { - parsed = strconv.Itoa(item.Parsed) - } - exportItem := model.ToyotaCalloffExcel{ - PlantNr: item.PlantNr, - DemandId: item.DemandId, - SupplierCode: item.SupplierCode, - ProjectId: item.ProjectId, - ProductFamilyId: item.ProductFamilyId, - TotalQty: item.TotalQty, - CheckSequence: item.CheckSequence, - Parsed: parsed, - OrderTime: item.OrderTime.Restore().Format(grmi.DateTimeOutFormat), - OrderShift: item.OrderShift, - } - li = append(li, exportItem) - } + head := make([]string, 0) - var exportItem model.ToyotaCalloffExcel - typeOf := reflect.TypeOf(exportItem) + var item model.ToyotaCalloff + typeOf := reflect.TypeOf(item) + indexLi := make([]int, 0) for i := 0; i < typeOf.NumField(); i++ { name, exist := tabNameMap[typeOf.Field(i).Name] - if !exist { - head = append(head, typeOf.Field(i).Name) - } else { + if exist { head = append(head, name) + indexLi = append(indexLi, i) } } - filepath, err = grmi.SaveExcelFile(li, head, "Sheet1", "顺引") + li := make([]map[string]interface{}, 0, len(result)) + for _, item := range result { + tv := reflect.ValueOf(item) + tf := reflect.TypeOf(item) + m := make(map[string]interface{}) + for _, index := range indexLi { + fieldName := tf.Field(index).Name + fieldValue := tv.FieldByName(fieldName).Interface() + k := tabNameMap[fieldName] + m[k] = fieldValue + } + li = append(li, m) + } + filepath, err = grmi.SaveExcelFileUseMap(li, head, "Sheet1", "发运校验") return } diff --git a/services/pln/implments/ToyotaCalloff.service.impl.go b/services/pln/implments/ToyotaCalloff.service.impl.go index ff4cb55..033b303 100644 --- a/services/pln/implments/ToyotaCalloff.service.impl.go +++ b/services/pln/implments/ToyotaCalloff.service.impl.go @@ -1316,13 +1316,12 @@ func (impl *ToyotaCalloffServiceImplement) ExportPageData(user *global.User, url } dao := dal.NewToyotaCalloffDAO(session, user.PlantNr, user.UserId) condition.Fill(urlParameters) - result, err := dao.SelectAndPaging(condition.Paging, predicates, condition.OrderByFields) + result, err := dao.SelectWithoutPaging(condition.Paging, predicates, condition.OrderByFields) if err != nil { return "", err } - data := result.Records.([]model.ToyotaCalloff) tabNameLi, err := tolnameDao.OriginSelect([]grmi.Predicate{ - baseMeta.TabColName_TabName.NewPredicate(grmi.Equal, "ToyotaCalloff"), + baseMeta.TabColName_TabName.NewPredicate(grmi.Equal, "PLN_ToyotaCalloff"), }, nil) if err != nil { return "", grmi.NewBusinessError("查询翻译数据失败, 错误:" + err.Error()) @@ -1342,37 +1341,30 @@ func (impl *ToyotaCalloffServiceImplement) ExportPageData(user *global.User, url for _, item := range stdefLi { stdefMap[item.StdefTyp] = item.Bez } - li := make([]interface{}, 0, len(data)) - for _, item := range data { - parsed, exist := stdefMap[strconv.Itoa(item.Parsed)] - if !exist { - parsed = strconv.Itoa(item.Parsed) - } - exportItem := model.ToyotaCalloffExcel{ - PlantNr: item.PlantNr, - DemandId: item.DemandId, - SupplierCode: item.SupplierCode, - ProjectId: item.ProjectId, - ProductFamilyId: item.ProductFamilyId, - TotalQty: item.TotalQty, - CheckSequence: item.CheckSequence, - Parsed: parsed, - OrderTime: item.OrderTime.Restore().Format(grmi.DateTimeOutFormat), - OrderShift: item.OrderShift, - } - li = append(li, exportItem) - } head := make([]string, 0) - var exportItem model.ToyotaCalloffExcel - typeOf := reflect.TypeOf(exportItem) + var item model.ToyotaCalloff + typeOf := reflect.TypeOf(item) + indexLi := make([]int, 0) for i := 0; i < typeOf.NumField(); i++ { name, exist := tabNameMap[typeOf.Field(i).Name] - if !exist { - head = append(head, typeOf.Field(i).Name) - } else { + if exist { head = append(head, name) + indexLi = append(indexLi, i) + } + } + li := make([]map[string]interface{}, 0, len(result)) + for _, item := range result { + tv := reflect.ValueOf(item) + tf := reflect.TypeOf(item) + m := make(map[string]interface{}) + for _, index := range indexLi { + fieldName := tf.Field(index).Name + fieldValue := tv.FieldByName(fieldName).Interface() + k := tabNameMap[fieldName] + m[k] = fieldValue } + li = append(li, m) } - filepath, err = grmi.SaveExcelFile(li, head, "Sheet1", "顺引") + filepath, err = grmi.SaveExcelFileUseMap(li, head, "Sheet1", "顺引") return -} +} \ No newline at end of file diff --git a/web/controllers/pln/ToyotaCalloff.rest.go b/web/controllers/pln/ToyotaCalloff.rest.go index bf70958..7aa56da 100644 --- a/web/controllers/pln/ToyotaCalloff.rest.go +++ b/web/controllers/pln/ToyotaCalloff.rest.go @@ -478,4 +478,22 @@ func RegisterToyotaCalloffCheck(party router.Party, path string, method func(*gl } supports.Ok(ctx, supports.OptionSuccess, nil) }) +} + +func RegisterExportShipCheck(party router.Party, path string, method func(*global.User, map[string]string) (string, error)) { + + party.Get(path, func(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + if !ok { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + + result, err := method(user, ctx.URLParams()) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, result) + }) } \ No newline at end of file diff --git a/web/controllers/pln/pln.go b/web/controllers/pln/pln.go index 3b83009..89d41ef 100644 --- a/web/controllers/pln/pln.go +++ b/web/controllers/pln/pln.go @@ -346,6 +346,8 @@ func RegisterRoutes() { RegisterToyotaCalloffCheck(toyotacalloff, "/check", serviceOfToyotaCalloff.Check) // ToyotaCalloff 发运校验查询多条并分页 RegisterQueryToyotaCalloff(toyotacalloff, "/checkquery", serviceOfToyotaCalloff.SelectAndPagingCheck) + // ToyotaCalloff 导出发运校验数据 + RegisterExportShipCheck(toyotacalloff, "/exportcheck", serviceOfToyotaCalloff.ExportPageDataCheck) // ToyotaCallOffErrorLst的路由组