123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package autocode
- import (
- "github.com/flipped-aurora/gin-vue-admin/server/global"
- "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
- "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
- autoCodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
- )
- type UnitService struct {
- }
- // CreateUnit 创建Unit记录
- // Author [piexlmax](https://github.com/piexlmax)
- func (unitService *UnitService) CreateUnit(unit autocode.Unit) (err error) {
- err = global.GVA_DB.Create(&unit).Error
- return err
- }
- // DeleteUnit 删除Unit记录
- // Author [piexlmax](https://github.com/piexlmax)
- func (unitService *UnitService)DeleteUnit(unit autocode.Unit) (err error) {
- err = global.GVA_DB.Delete(&unit).Error
- return err
- }
- // DeleteUnitByIds 批量删除Unit记录
- // Author [piexlmax](https://github.com/piexlmax)
- func (unitService *UnitService)DeleteUnitByIds(ids request.IdsReq) (err error) {
- err = global.GVA_DB.Delete(&[]autocode.Unit{},"id in ?",ids.Ids).Error
- return err
- }
- // UpdateUnit 更新Unit记录
- // Author [piexlmax](https://github.com/piexlmax)
- func (unitService *UnitService)UpdateUnit(unit autocode.Unit) (err error) {
- err = global.GVA_DB.Save(&unit).Error
- return err
- }
- // GetUnit 根据id获取Unit记录
- // Author [piexlmax](https://github.com/piexlmax)
- func (unitService *UnitService)GetUnit(id uint) (err error, unit autocode.Unit) {
- err = global.GVA_DB.Where("id = ?", id).First(&unit).Error
- return
- }
- // GetUnitInfoList 分页获取Unit记录
- // Author [piexlmax](https://github.com/piexlmax)
- func (unitService *UnitService)GetUnitInfoList(info autoCodeReq.UnitSearch) (err error, list interface{}, total int64) {
- limit := info.PageSize
- offset := info.PageSize * (info.Page - 1)
- // 创建db
- db := global.GVA_DB.Model(&autocode.Unit{})
- var units []autocode.Unit
- // 如果有条件搜索 下方会自动创建搜索语句
- err = db.Count(&total).Error
- err = db.Limit(limit).Offset(offset).Find(&units).Error
- return err, units, total
- }
|