2024-05-09 09:51:58 +08:00
|
|
|
package sql_builder
|
2024-04-29 15:59:38 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
2024-05-09 09:51:58 +08:00
|
|
|
"time"
|
2024-04-29 15:59:38 +08:00
|
|
|
|
2024-05-07 17:19:55 +08:00
|
|
|
_ "git.botann.com/lijun/sql-builder/conf"
|
2024-04-29 15:59:38 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
type Page struct {
|
|
|
|
Total int `json:"total" form:"total"`
|
|
|
|
PageIndex int `json:"pageIndex" form:"pageIndex"`
|
|
|
|
PageSize int `json:"pageSize" form:"pageSize"`
|
|
|
|
Data interface{} `json:"data" form:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Page) Init() {
|
|
|
|
if p.PageIndex == 0 {
|
|
|
|
p.SetPageIndex(1)
|
|
|
|
}
|
|
|
|
if p.PageSize == 0 {
|
2024-05-08 15:53:39 +08:00
|
|
|
p.SetPageSize(10)
|
2024-04-29 15:59:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Page) GetPageIndex() int {
|
|
|
|
return p.PageIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Page) GetPageSize() int {
|
|
|
|
return p.PageSize
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Page) GetTotal() int {
|
|
|
|
return p.Total
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Page) SetTotal(total int) {
|
|
|
|
p.Total = total
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Page) SetPageIndex(pageIndex int) {
|
|
|
|
p.PageIndex = pageIndex
|
|
|
|
}
|
|
|
|
|
2024-05-08 15:53:39 +08:00
|
|
|
func (p *Page) SetPageSize(pageSize int) {
|
2024-04-29 15:59:38 +08:00
|
|
|
p.PageSize = pageSize
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMain(m *testing.M) {
|
2024-05-28 14:18:21 +08:00
|
|
|
type PreliminaryProcedureResponse struct {
|
|
|
|
ProjectId int `json:"project_id"`
|
|
|
|
InitiationTime time.Time `json:"initiation_time" export:"x:1,y:2"`
|
|
|
|
ProjectNo string `json:"project_no" export:"x:2,y:2"`
|
|
|
|
ProjectName string `json:"project_name" export:"x:3,y:2"`
|
|
|
|
ProjectUnit string `json:"project_unit" export:"x:4,y:2"`
|
|
|
|
ProjectType string `json:"project_type" export:"x:5,y:2"`
|
|
|
|
Allnum int `json:"all_num" export:"x:6,y:2"`
|
|
|
|
NotHandleNum int `json:"not_handle_num" export:"x:7,y:2"`
|
|
|
|
NoHandleNum int `json:"no_handle_num" export:"x:8,y:2"`
|
|
|
|
HandlingNum int `json:"handling_num" export:"x:9,y:2"`
|
|
|
|
HandledNum int `json:"handled_num" export:"x:10,y:2"`
|
2024-04-29 15:59:38 +08:00
|
|
|
}
|
2024-05-28 14:18:21 +08:00
|
|
|
var data []PreliminaryProcedureResponse
|
|
|
|
company_id := 1
|
2024-05-09 09:51:58 +08:00
|
|
|
sqlb := DefaultSqlBuilder()
|
2024-05-28 14:18:21 +08:00
|
|
|
slqs := `select t1.autoseq,max(t1.establishment_time),max(t1.number),max(t1.name),max(t2.name) as project_unit,max(t3.name) as project_type,
|
2024-05-09 09:51:58 +08:00
|
|
|
count(distinct t6.autoseq) all_num,
|
|
|
|
count(distinct case t6.state when 1 then t6.autoseq end) not_handle_num,
|
|
|
|
count(distinct case t6.state when 2 then t6.autoseq end) no_handle_num,
|
|
|
|
count(distinct case t6.state when 3 then t6.autoseq end) handling_num,
|
|
|
|
count(distinct case t6.state when 4 then t6.autoseq end) handled_num
|
|
|
|
from tproject_info t1
|
2024-05-28 14:18:21 +08:00
|
|
|
inner join tcompany t2 on t1.investor_id = t2.autoseq and t2.del = 0 @c
|
2024-05-09 09:51:58 +08:00
|
|
|
left join tinvestment_type t3 on t1.industry_category_id = t3.autoseq and t3.del = 0
|
2024-05-28 14:18:21 +08:00
|
|
|
left join tpreliminary_procedures t6 on t1.autoseq = t6.project_id
|
|
|
|
where t1.del = 0 @c @c @c @c @c
|
2024-05-09 09:51:58 +08:00
|
|
|
group by t1.autoseq`
|
|
|
|
sqlb.Sql = slqs
|
2024-05-28 14:18:21 +08:00
|
|
|
if company_id != 0 {
|
|
|
|
sqlb.Conditions("t2.autoseq = ?", company_id)
|
2024-05-09 09:51:58 +08:00
|
|
|
}
|
2024-05-28 14:18:21 +08:00
|
|
|
fmt.Println(sqlb)
|
2024-05-09 09:51:58 +08:00
|
|
|
var err error
|
2024-05-28 14:18:21 +08:00
|
|
|
page := Page{PageIndex: 2, PageSize: 10}
|
|
|
|
err = sqlb.PaginateBySql(&data, &page)
|
2024-04-29 15:59:38 +08:00
|
|
|
page.Data = &data
|
2024-05-09 09:51:58 +08:00
|
|
|
fmt.Println(err, page.Data)
|
2024-04-29 15:59:38 +08:00
|
|
|
}
|