123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package autocode
- import (
- "github.com/flipped-aurora/gin-vue-admin/server/global"
- "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
- autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
- "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
- "gorm.io/gorm"
- "time"
- )
- type UnitService struct {
- }
- func (unitService *UnitService) CreateUnit(unit autocode.Unit) (err error) {
- err = global.GVA_DB.Create(&unit).Error
- return err
- }
- func (unitService *UnitService) DeleteUnit(unit autocode.Unit) (err error) {
- err = global.GVA_DB.Delete(&unit).Error
- return err
- }
- func (unitService *UnitService) DeleteUnitByIds(ids request.IdsReq) (err error) {
- err = global.GVA_DB.Delete(&[]autocode.Unit{}, "id in ?", ids.Ids).Error
- return err
- }
- func (unitService *UnitService) UpdateUnit(unit autocode.Unit) (err error) {
- now := *unit.UnitIntegral
- now = now * 10
- unit.UnitIntegral = &now
- err = global.GVA_DB.Save(&unit).Error
- return err
- }
- func (unitService *UnitService) UpdateUnitNext(unit autocode.Unit) (err error) {
-
- now := *unit.UnitIntegral
- now = now * 10
- unit.UnitIntegral = &now
- global.GVA_DB.Session(&gorm.Session{
- AllowGlobalUpdate: true,
- }).Model(&unit).Updates(&autocode.Unit{UnitMaxIntegral: unit.UnitIntegral, UnitIntegral: unit.UnitIntegral, Period: time.Now().Format("20060102150405")})
- return err
- }
- func (unitService *UnitService) UpdateUnitA(unit autocode.Unit) (err error) {
- err = global.GVA_DB.Save(&unit).Error
- return err
- }
- func (unitService *UnitService) GetUnit(id uint) (err error, unit autocode.Unit) {
- err = global.GVA_DB.Where("id = ?", id).First(&unit).Error
- return
- }
- func (unitService *UnitService) GetUnitTop() (err error, unit autocode.Unit) {
- top := autocode.Unit{}
- err = global.GVA_DB.First(&top).Error
- return err, top
- }
- func (unitService *UnitService) GetUnitInfoList(info autoCodeReq.UnitSearch) (err error, list interface{}, total int64) {
- limit := info.PageSize
- offset := info.PageSize * (info.Page - 1)
-
- db := global.GVA_DB.Model(&autocode.Unit{})
- if info.UnitName != "" {
- db.Where("unit_name like ?", "%"+info.UnitName+"%")
- }
- var units []autocode.Unit
-
- err = db.Count(&total).Error
- err = db.Limit(limit).Offset(offset).Find(&units).Error
- return err, units, total
- }
- func (unitService *UnitService) GetUnitInfoListAll() (err error, list []autocode.Unit) {
- var units []autocode.Unit
-
- err = global.GVA_DB.Model(&autocode.Unit{}).Find(&units).Error
- return err, units
- }
|