-
Notifications
You must be signed in to change notification settings - Fork 0
/
privateservice.go
49 lines (46 loc) · 2.04 KB
/
privateservice.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package privateservice
import (
"github.com/Junvary/gin-quasar-admin/GQA-BACKEND/gqaplugin/attendance/global"
"github.com/Junvary/gin-quasar-admin/GQA-BACKEND/gqaplugin/attendance/model"
gqaModel "github.com/Junvary/gin-quasar-admin/GQA-BACKEND/model"
"gorm.io/gorm"
"strconv"
"time"
)
func InareaWithUserinfoList(inareaWithUserinfoDateRequest model.InareaWithUserinfoDateRequest) (err error, result []model.InareaWithUserinfo, total int64) {
pageSize := inareaWithUserinfoDateRequest.PageSize
offset := inareaWithUserinfoDateRequest.PageSize * (inareaWithUserinfoDateRequest.Page - 1)
var resultList []model.InareaWithUserinfo
var db *gorm.DB
db = global.AttendanceDb.Model(&model.Inarea{})
if inareaWithUserinfoDateRequest.InAreaTime != "" {
db = db.Where("InAreaTime like ?", inareaWithUserinfoDateRequest.InAreaTime+"%")
}
db = db.Order(gqaModel.OrderByColumn("InAreaTime", false))
db = db.Select("*").Joins("left join userinfo on userinfo.`GUID` = inarea.`UserGUID`").Scan(&resultList)
if inareaWithUserinfoDateRequest.WorkNumber != "" {
db = db.Where("WorkNumber = ?", inareaWithUserinfoDateRequest.WorkNumber)
}
if inareaWithUserinfoDateRequest.UserName != "" {
db = db.Where("UserName = ?", inareaWithUserinfoDateRequest.UserName)
}
err = db.Count(&total).Error
if err != nil {
return
}
err = db.Limit(pageSize).Offset(offset).Find(&resultList).Error
return err, resultList, total
}
func InareaWithUserinfoYear(inareaWithUserinfoYearRequest model.InareaWithUserinfoYearRequest) (err error, record []model.InareaWithUserinfo) {
var resultList []model.InareaWithUserinfo
var db *gorm.DB
db = global.AttendanceDb.Model(&model.Inarea{})
db = db.Where("InAreaTime like ? ", strconv.Itoa(time.Now().Year())+"-%")
db = db.Order("substr(InAreaTime, 12)")
db = db.Select("*").Joins("left join userinfo on userinfo.`GUID` = inarea.`UserGUID`").Scan(&resultList)
if inareaWithUserinfoYearRequest.WorkNumber != "" {
db = db.Where("WorkNumber = ?", inareaWithUserinfoYearRequest.WorkNumber)
}
err = db.First(&resultList).Error
return err, resultList
}