123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- package announcement_management
- import (
- "adm-management/errors"
- v1 "adm-management/pb/v1"
- "context"
- "reflect"
- "encoding/json"
- "fmt"
- "git.getensh.com/common/gopkgsv2/database"
- "git.getensh.com/common/gopkgsv2/logger"
- "go.uber.org/zap"
- "google.golang.org/grpc/status"
- "gorm.io/gorm"
- )
- type Edit struct {
- ModelNo string `gorm:"column:model_no" json:"model_no" form:"model_no"`
- VehicleBatch string `gorm:"column:vehicle_batch" json:"vehicle_batch" form:"vehicle_batch"`
- BrandName string `gorm:"column:brand_name" json:"brand_name" form:"brand_name"`
- VehicleTypeDetail string `gorm:"column:vehicle_type_detail" json:"vehicle_type_detail" form:"vehicle_type_detail"`
- ApprovedLoad string `gorm:"column:approved_load" json:"approved_load" form:"approved_load"`
- GrossMass string `gorm:"column:gross_mass" json:"gross_mass" form:"gross_mass"`
- UnladenMass string `gorm:"column:unladen_mass" json:"unladen_mass" form:"unladen_mass"`
- FuelTypeDetail string `gorm:"column:fuel_type_detail" json:"fuel_type_detail" form:"fuel_type_detail"`
- AxleNumber string `gorm:"column:axle_number" json:"axle_number" form:"axle_number"`
- EmissionStandard string `gorm:"column:emission_standard" json:"emission_standard" form:"emission_standard"`
- Wheelbase string `gorm:"column:wheelbase" json:"wheelbase" form:"wheelbase"`
- AxleWeight string `gorm:"column:axle_weight" json:"axle_weight" form:"axle_weight"`
- NumberOfLeafSprings string `gorm:"column:number_of_leaf_springs" json:"number_of_leaf_springs" form:"number_of_leaf_springs"`
- TyreNumber string `gorm:"column:tyre_number" json:"tyre_number" form:"tyre_number"`
- TyreSize string `gorm:"column:tyre_size" json:"tyre_size" form:"tyre_size"`
- ApproachingDepartureAngle string `gorm:"column:approaching_departure_angle" json:"approaching_departure_angle" form:"approaching_departure_angle"`
- FrontBackSuspention string `gorm:"column:front_back_suspention" json:"front_back_suspention" form:"front_back_suspention"`
- FrontWheelDistance string `gorm:"column:front_wheel_distance" json:"front_wheel_distance" form:"front_wheel_distance"`
- BackWheelDistance string `gorm:"column:back_wheel_distance" json:"back_wheel_distance" form:"back_wheel_distance"`
- VinRules string `gorm:"column:vin_rules" json:"vin_rules" form:"vin_rules"`
- Long string `gorm:"column:long" json:"long" form:"long"`
- Wide string `gorm:"column:wide" json:"wide" form:"wide"`
- High string `gorm:"column:high" json:"high" form:"high"`
- CargoLong string `gorm:"column:cargo_long" json:"cargo_long" form:"cargo_long"`
- CargoWide string `gorm:"column:cargo_wide" json:"cargo_wide" form:"cargo_wide"`
- CargoHigh string `gorm:"column:cargo_high" json:"cargo_high" form:"cargo_high"`
- TopSpeed string `gorm:"column:top_speed" json:"top_speed" form:"top_speed"`
- ApprovedNumber string `gorm:"column:approved_number" json:"approved_number" form:"approved_number"`
- NumberOfPassengers string `gorm:"column:number_of_passengers" json:"number_of_passengers" form:"number_of_passengers"`
- SteeringMode string `gorm:"column:steering_mode" json:"steering_mode" form:"steering_mode"`
- TractionMass string `gorm:"column:traction_mass" json:"traction_mass" form:"traction_mass"`
- LoadMassCoefficient string `gorm:"column:load_mass_coefficient" json:"load_mass_coefficient" form:"load_mass_coefficient"`
- SemitrailerSaddleMaxAllowGrossMass string `gorm:"column:semitrailer_saddle_max_allow_gross_mass" json:"semitrailer_saddle_max_allow_gross_mass" form:"semitrailer_saddle_max_allow_gross_mass"`
- CompanyName string `gorm:"column:company_name" json:"company_name" form:"company_name"`
- CompanyAddress string `gorm:"column:company_address" json:"company_address" form:"company_address"`
- }
- type field struct {
- Eng string `gorm:"column:field" json:"eng" form:"eng"`
- Chi string `gorm:"column:desc" json:"chi" form:"chi"`
- }
- func EditList(ctx context.Context, req *v1.EditRequest) (reply *v1.EditReply, err error) {
- defer func() {
- if r := recover(); r != nil {
- err = fmt.Errorf("%+v", r)
- e := &status.Status{}
- if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
- logger.Error("err",
- zap.String("system_err", err.Error()),
- zap.Stack("stacktrace"))
- }
- }
- }()
- reply = &v1.EditReply{}
- db := database.DB()
- detail := Edit{}
- err = db.Raw("SELECT model_no, vehicle_batch, brand_name, vehicle_type_detail, approved_load, gross_mass, unladen_mass, fuel_type_detail, axle_number, emission_standard, wheelbase, axle_weight, number_of_leaf_springs, tyre_number, tyre_size, approaching_departure_angle, front_back_suspention, front_wheel_distance, back_wheel_distance, vin_rules, `long`, wide, high, cargo_long, cargo_wide, cargo_high, top_speed, approved_number, number_of_passengers, steering_mode, traction_mass, load_mass_coefficient, semitrailer_saddle_max_allow_gross_mass, company_name, company_address FROM db_adm_dws.t_adm_dws16 where vehicle_batch = ? and model_no = ?", req.VehicleBatch, req.ModelNo).Find(&detail).Error
- if err != nil {
- if err == gorm.ErrRecordNotFound {
- return reply, nil
- }
- return reply, errors.SystemError
- }
- var list []*v1.EditList
- t := reflect.TypeOf(detail)
- v := reflect.ValueOf(detail)
- var fields []field
- err = db.Raw("select field, `desc` from db_adm_management.t_adm_field_management where field in ('model_no', 'vehicle_batch', 'brand_name', 'vehicle_type_detail', 'approved_load', 'gross_mass', 'unladen_mass', 'fuel_type_detail', 'axle_number', 'emission_standard', 'wheelbase', 'axle_weight', 'number_of_leaf_springs', 'tyre_number', 'tyre_size', 'approaching_departure_angle', 'front_back_suspention', 'front_wheel_distance', 'back_wheel_distance', 'vin_rules', 'long', 'wide', 'high', 'cargo_long', 'cargo_wide', 'cargo_high', 'top_speed', 'approved_number', 'number_of_passengers', 'steering_mode', 'traction_mass', 'load_mass_coefficient', 'semitrailer_saddle_max_allow_gross_mass', 'company_name', 'company_address')").Find(&fields).Error
- maps := make(map[string]string)
- for _, v := range fields {
- maps[v.Eng] = v.Chi
- }
- for i := 0; i < t.NumField(); i++ {
- list = append(list, &v1.EditList{
- Key: t.Field(i).Tag.Get("json"),
- Desc: maps[t.Field(i).Tag.Get("json")],
- Value: v.Field(i).Interface().(string),
- })
- }
- reply.List = list
- return reply, nil
- }
|