main
parent
049d3160f4
commit
7a09571fdc
@ -0,0 +1,15 @@
|
||||
package manage
|
||||
|
||||
type StudentInsureInfoQueryRequest struct {
|
||||
SchoolName string `json:"schoolName" form:"schoolName"`
|
||||
StudentName string `json:"studentName" form:"studentName"`
|
||||
StudentIdentityNo string `json:"studentIdentityNo" form:"studentIdentityNo"`
|
||||
ParentName string `json:"parentName" form:"parentName"`
|
||||
College string `json:"college" form:"college"`
|
||||
Speciality string `json:"speciality" form:"speciality"`
|
||||
Class string `json:"class" form:"class"`
|
||||
ParentIdentityNo string `json:"parentIdentityNo" form:"parentIdentityNo"`
|
||||
ParentMobile string `json:"parentMobile" form:"parentMobile"`
|
||||
UpdatedAtStart string `json:"updatedAtStart" form:"updatedAtStart"`
|
||||
UpdatedAtEnd string `json:"updatedAtEnd" form:"updatedAtEnd"`
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package request
|
||||
|
||||
type StudentInsureInfoRequest struct {
|
||||
SchoolName string `json:"schoolName" form:"schoolName"`
|
||||
StudentName string `json:"studentName" form:"studentName"`
|
||||
StudentIdentityNo string `json:"studentIdentityNo" form:"studentIdentityNo"`
|
||||
StudentIdentityType uint `json:"studentIdentityType" form:"studentIdentityType"`
|
||||
ParentName string `json:"parentName" form:"parentName"`
|
||||
College string `json:"college" form:"college"`
|
||||
Speciality string `json:"speciality" form:"speciality"`
|
||||
Class string `json:"class" form:"class"`
|
||||
Relation string `json:"relation" form:"relation"`
|
||||
ParentIdentityNo string `json:"parentIdentityNo" form:"parentIdentityNo"`
|
||||
ParentIdentityType uint `json:"parentIdentityType" form:"parentIdentityType"`
|
||||
ParentMobile string `json:"parentMobile" form:"parentMobile"`
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
)
|
||||
|
||||
type StudentInsureInfo struct {
|
||||
ID int
|
||||
SchoolName string
|
||||
StudentName string
|
||||
StudentIdentityNo string
|
||||
StudentIdentityType uint
|
||||
ParentName string
|
||||
College string
|
||||
Speciality string
|
||||
Class string
|
||||
Relation string
|
||||
ParentIdentityNo string
|
||||
ParentIdentityType uint
|
||||
ParentMobile string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time `json:"-"`
|
||||
}
|
||||
|
||||
func (StudentInsureInfo) TableName() string {
|
||||
return "student_insure_info"
|
||||
}
|
||||
|
||||
func (a StudentInsureInfo) MarshalJSON() ([]byte, error) {
|
||||
type Alias StudentInsureInfo
|
||||
return json.Marshal(&struct {
|
||||
CreatedAt string
|
||||
UpdatedAt string
|
||||
*Alias
|
||||
}{
|
||||
CreatedAt: a.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
UpdatedAt: a.UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
Alias: (*Alias)(&a),
|
||||
})
|
||||
}
|
@ -0,0 +1,150 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xuri/excelize/v2"
|
||||
"gorm.io/gorm"
|
||||
"insure/dto/request"
|
||||
"insure/dto/request/manage"
|
||||
"insure/global"
|
||||
"insure/model"
|
||||
"insure/utils/excel"
|
||||
"time"
|
||||
)
|
||||
|
||||
var StudentInsureService = studentInsureService{}
|
||||
|
||||
type studentInsureService struct {
|
||||
}
|
||||
|
||||
func (s *studentInsureService) Save(r request.StudentInsureInfoRequest) (*model.StudentInsureInfo, error) {
|
||||
info := model.StudentInsureInfo{}
|
||||
info.SchoolName = r.SchoolName
|
||||
info.StudentName = r.StudentName
|
||||
info.StudentIdentityNo = r.StudentIdentityNo
|
||||
info.StudentIdentityType = r.StudentIdentityType
|
||||
info.College = r.College
|
||||
info.Speciality = r.Speciality
|
||||
info.Class = r.Class
|
||||
info.Relation = r.Relation
|
||||
info.ParentName = r.ParentName
|
||||
info.ParentIdentityNo = r.ParentIdentityNo
|
||||
info.ParentIdentityType = r.ParentIdentityType
|
||||
info.ParentMobile = r.ParentMobile
|
||||
err := global.DB.Save(&info).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &info, nil
|
||||
}
|
||||
|
||||
func (s *studentInsureService) GetInfos(req manage.OrderQueryRequest) ([]model.StudentInsureInfo, int64) {
|
||||
records := make([]model.StudentInsureInfo, req.PageSize)
|
||||
offset := (req.Page - 1) * req.PageSize
|
||||
var total int64
|
||||
s.buildQuery(req).Order("id desc").Offset(offset).Limit(req.PageSize).Find(&records)
|
||||
s.buildQuery(req).Model(&model.Order{}).Count(&total)
|
||||
return records, total
|
||||
}
|
||||
func (s *studentInsureService) buildQuery(req manage.StudentInsureInfoQueryRequest) *gorm.DB {
|
||||
tx := global.DB
|
||||
if req.SchoolName != "" {
|
||||
tx = tx.Where("school_name", req.SchoolName)
|
||||
}
|
||||
if req.StudentName != "" {
|
||||
tx = tx.Where("student_name", req.StudentName)
|
||||
}
|
||||
if req.StudentIdentityNo != "" {
|
||||
tx = tx.Where("student_identity_no", req.StudentIdentityNo)
|
||||
}
|
||||
if req.ParentName != "" {
|
||||
tx = tx.Where("parent_name", req.ParentName)
|
||||
}
|
||||
if req.ParentIdentityNo != "" {
|
||||
tx = tx.Where("parent_identity_no", req.ParentIdentityNo)
|
||||
}
|
||||
if req.ParentMobile != "" {
|
||||
tx = tx.Where("parent_mobile", req.ParentMobile)
|
||||
}
|
||||
if req.College != "" {
|
||||
tx = tx.Where("college", req.College)
|
||||
}
|
||||
if req.Speciality != "" {
|
||||
tx = tx.Where("speciality", req.Speciality)
|
||||
}
|
||||
if req.Class != "" {
|
||||
tx = tx.Where("class", req.Class)
|
||||
}
|
||||
if req.UpdatedAtStart != "" && req.UpdatedAtEnd != "" {
|
||||
updatedAtStart := req.UpdatedAtStart + " 00:00:00"
|
||||
updatedAtEnd := req.UpdatedAtEnd + " 23:59:59"
|
||||
tx = tx.Where("updated_at >= ?", updatedAtStart).Where("updated_at <= ?", updatedAtEnd)
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
func (s *studentInsureService) GenerateOrdersExcel(req manage.StudentInsureInfoQueryRequest) *excelize.File {
|
||||
pageSize := 200
|
||||
lastID := 0
|
||||
|
||||
f := excel.NewFile()
|
||||
headers := []string{
|
||||
"学校名称",
|
||||
"学生姓名",
|
||||
"学生证件号",
|
||||
"学生证件类型",
|
||||
"学院",
|
||||
"专业",
|
||||
"班级",
|
||||
"家长与学生关系",
|
||||
"家长姓名",
|
||||
"家长证件号",
|
||||
"家长证件类型",
|
||||
"家长电话",
|
||||
"提交时间",
|
||||
}
|
||||
excel.SetSimpleHeaders(headers, "Sheet1", f)
|
||||
|
||||
var allRecords []model.StudentInsureInfo
|
||||
for {
|
||||
records := make([]model.StudentInsureInfo, pageSize)
|
||||
s.buildQuery(req).
|
||||
Where("id > ?", lastID).
|
||||
Order("id asc").
|
||||
Limit(pageSize).
|
||||
Find(&records)
|
||||
count := len(records)
|
||||
if count == 0 {
|
||||
break
|
||||
}
|
||||
lastIndex := count - 1
|
||||
lastID = records[lastIndex].ID
|
||||
fmt.Println("lastID", lastID)
|
||||
allRecords = append(allRecords, records...)
|
||||
}
|
||||
|
||||
s.buildOrdersExcel(allRecords, "Sheet1", f)
|
||||
|
||||
return f
|
||||
}
|
||||
|
||||
func (studentInsureService) buildOrdersExcel(records []model.StudentInsureInfo, sheet string, f *excelize.File) {
|
||||
row := 2
|
||||
for _, record := range records {
|
||||
col := 0
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.SchoolName)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.StudentName)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.StudentIdentityNo)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), "身份证")
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.College)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.Speciality)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.Class)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.Relation)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.ParentName)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.ParentIdentityNo)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), "身份证")
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.ParentMobile)
|
||||
f.SetCellValue(sheet, excel.CellKey(row, &col), record.UpdatedAt.Format(time.DateTime))
|
||||
row++
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue