package supply_analysis import ( "eta_gn/eta_api/global" "eta_gn/eta_api/utils" "time" ) // VarietyPlant variety_plant 品种装置表 type VarietyPlant struct { VarietyPlantId int `orm:"column(variety_plant_id);pk" gorm:"primaryKey" ` VarietyId int `description:"品种id"` Province string `description:"所属省份"` City string `description:"所属城市"` FactoryName string `description:"工厂名称"` PlantName string `description:"装置/产线名称"` MaintenanceDate time.Time `description:"检修日期"` ResumptionDate time.Time `description:"复产日期"` AnnualCapacity float64 `description:"年产能"` Coefficient float64 `description:"降负系数"` AverageDailyCapacityReduction float64 `description:"日均产量减量"` IsStop int `description:"是否停产,0:未停产;1:停产;默认未停产"` Sort int `description:"排序字段,越小越靠前"` SysUserId int `description:"添加人id"` SysUserRealName string `description:"添加人真实姓名"` ModifyTime time.Time `description:"最近一次更新时间"` CreateTime time.Time `description:"添加时间"` } // AddVarietyPlant 添加variety_plant装置 func AddVarietyPlant(item *VarietyPlant) (err error) { err = global.DmSQL["data"].Create(item).Error return } // MultiAddVarietyPlant 批量添加variety_plant装置 func MultiAddVarietyPlant(items []*VarietyPlant) (err error) { err = global.DmSQL["data"].CreateInBatches(items, utils.MultiAddNum).Error return } // Update 更新基础信息 func (varietyPlant *VarietyPlant) Update(cols []string) (err error) { err = global.DmSQL["data"].Select(cols).Updates(varietyPlant).Error return } // GetVarietyPlantById 根据品种装置id获取品种装置详情 func GetVarietyPlantById(id int) (item *VarietyPlant, err error) { sql := `SELECT * FROM variety_plant WHERE variety_plant_id = ?` err = global.DmSQL["data"].Raw(sql, id).First(&item).Error return } // GetVarietyPlantByIdList 根据品种装置id列表获取品种装置详情列表 func GetVarietyPlantByIdList(idList []int) (items []*VarietyPlant, err error) { num := len(idList) if num <= 0 { return } sql := `SELECT * FROM variety_plant WHERE variety_plant_id in (` + utils.GetOrmInReplace(num) + `)` err = global.DmSQL["data"].Raw(sql, idList).Scan(&items).Error return } // VarietyPlantItem 品种装置数据(展示使用) type VarietyPlantItem struct { VarietyPlantId int `orm:"column(variety_plant_id);pk" gorm:"primaryKey" ` VarietyId int `description:"品种id"` Province string `description:"所属省份"` City string `description:"所属城市"` FactoryName string `description:"工厂名称"` PlantName string `description:"装置/产线名称"` MaintenanceDate string `description:"检修日期"` ResumptionDate string `description:"复产日期"` AnnualCapacity float64 `description:"年产能"` Coefficient float64 `description:"降负系数"` AverageDailyCapacityReduction float64 `description:"日均产量减量"` Day int `description:"时长"` CapacityReduction float64 `description:"期间减量"` IsStop int `description:"是否停产,0:未停产;1:停产;默认未停产"` Sort int `description:"排序字段,越小越靠前"` SysUserId int `description:"添加人id"` SysUserRealName string `description:"添加人真实姓名"` ModifyTime string `description:"最近一次更新时间"` CreateTime string `description:"添加时间"` Button VarietyPlantButton `gorm:"-" description:"操作按钮权限"` } type VarietyPlantButton struct { Edit bool `description:"操作权限"` Delete bool `description:"删除权限"` } // GetAllVarietyPlantByVarietyId 根据品种id获取所有的装置 func GetAllVarietyPlantByVarietyId(varietyId int) (items []*VarietyPlantItem, err error) { sql := `SELECT * FROM variety_plant a WHERE variety_id = ? ORDER BY sort ASC, variety_plant_id ASC ` err = global.DmSQL["data"].Raw(sql, varietyId).Scan(&items).Error return } // GetCountVarietyPlantByVarietyId 根据品种id获取所有的装置数量 func GetCountVarietyPlantByVarietyId(varietyId int) (total int, err error) { sql := `SELECT count(1) total FROM variety_plant a WHERE variety_id = ? ` err = global.DmSQL["data"].Raw(sql, varietyId).Scan(&total).Error return } // DeleteVarietyPlantById 根据装置id删除 func DeleteVarietyPlantById(id int) (err error) { sql := `DELETE FROM variety_plant WHERE variety_plant_id = ?` err = global.DmSQL["data"].Exec(sql, id).Error return } // UpdateEdbInfoSortByPrevId 根据上一层级id更新排序 func UpdateEdbInfoSortByPrevId(varietyId, prevVarietyId, nowSort int, updateSort string) (err error) { sql := `UPDATE variety_plant set sort = ` + updateSort + ` WHERE variety_id=? AND ` if prevVarietyId > 0 { sql += ` ( sort > ? or ( sort=? AND variety_plant_id > ?)) ` } err = global.DmSQL["data"].Exec(sql, varietyId, nowSort, nowSort, prevVarietyId).Error return } // UpdateEdbInfoSortByNextId 根据下一层级id更新排序 func UpdateEdbInfoSortByNextId(varietyId, prevVarietyId, nowSort int, updateSort string) (err error) { sql := `UPDATE variety_plant set sort = ` + updateSort + ` WHERE variety_id=? AND ` if prevVarietyId > 0 { sql += ` ( sort < ? or ( sort=? AND variety_plant_id < ? )) ` } err = global.DmSQL["data"].Exec(sql, varietyId, nowSort, nowSort, prevVarietyId).Error return } func (m *VarietyPlantItem) ConvertToResp() { m.CreateTime = utils.GormDateStrToDateStr(m.CreateTime) m.ModifyTime = utils.GormDateStrToDateStr(m.ModifyTime) m.MaintenanceDate = utils.GormDateStrToDateStr(m.MaintenanceDate) m.ResumptionDate = utils.GormDateStrToDateStr(m.ResumptionDate) return }