123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- * @description: 安全巡检数据库操作相关
- * @Author: LanJianRong
- * @Date: 2020-11-20
- * @FilePath: \construction_management\dao\Quality_dao.go
- */
- package dao
- import (
- "fmt"
- "github.com/go-xorm/xorm"
- "go.mod/models"
- )
- //数据库操作引擎
- type QualityDao struct {
- engine *xorm.Engine
- }
- //获得一个DAO对象
- func NewQualityDao(engine *xorm.Engine) *QualityDao {
- return &QualityDao{
- engine: engine,
- }
- }
- func (d *QualityDao) FindById(id int) *models.CmQuality {
- data := &models.CmQuality{Id: id}
- ok, err := d.engine.Get(data)
- if ok && err == nil {
- return data
- } else {
- data.Id = 0
- return data
- }
- }
- // id获得数据
- func (d *QualityDao) GetListByBid(id int, pageNo int, pageSize int) ([]models.CmQuality, int64) {
- dataList := make([]models.CmQuality, 0)
- start := (pageNo - 1) * pageSize
- total, err := d.engine.
- Where("bidsection_id=?", id).
- Asc("id").
- Limit(pageSize, start).
- FindAndCount(&dataList)
- if err != nil {
- return dataList, 0
- }
- return dataList, total
- }
- // 插入单条记录
- func (d *QualityDao) InsertRecord(data models.CmQuality) (bool, error) {
- affected, err := d.engine.InsertOne(data)
- return affected > 0, err
- }
- // 删除记录
- func (d *QualityDao) DeleteRecord(id int) (bool, error) {
- Quality := models.CmQuality{}
- affected, err := d.engine.Id(id).Delete(Quality)
- return affected > 0, err
- }
- // 根据code获取记录
- func (d *QualityDao) FindByCode(code string) bool {
- data := &models.CmQuality{Code: code}
- has, _ := d.engine.Get(data)
- return has
- }
- // 筛选出应用了当前规则的条数
- func (d *QualityDao) CountRuleCode(bid int) (int64, error) {
- data := &models.CmQuality{}
- total, err := d.engine.Where("`bidsection_id` = ?", bid).Count(data)
- if err != nil {
- total = 0
- }
- return total, err
- }
- // 更改status
- func (d *QualityDao) ChangeStatus(id int, status int) error {
- data := &models.CmQuality{Status: status}
- _, err := d.engine.ID(id).Update(data)
- return err
- }
- // 获得某状态下的安全
- func (d *QualityDao) GetStatus(bidsectionId int, status int) []models.CmQuality {
- datalist := make([]models.CmQuality, 0)
- _ = d.engine.
- Where("bidsection_id = ? and status=? ", bidsectionId, status).
- Desc("id").
- Find(&datalist)
- return datalist
- }
- // 获得某年份下的安全
- func (d *QualityDao) GetTypeYear(bidsectionId int, year int) []models.CmQuality {
- startYear := fmt.Sprintf("%d-01-01:00.00.00", year)
- endYear := fmt.Sprintf("%d-12-31:23.59.59", year)
- datalist := make([]models.CmQuality, 0)
- _ = d.engine.
- Where("bidsection_id = ? and create_time>='"+startYear+"' and create_time<='"+endYear+"' ", bidsectionId).
- Desc("id").
- Find(&datalist)
- return datalist
- }
|