99 lines
2.8 KiB
Go
99 lines
2.8 KiB
Go
package sql_builder
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
"time"
|
|
|
|
_ "git.botann.com/lijun/sql-builder/conf"
|
|
)
|
|
|
|
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 {
|
|
p.SetPageSize(10)
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (p *Page) SetPageSize(pageSize int) {
|
|
p.PageSize = pageSize
|
|
}
|
|
|
|
func TestMain(m *testing.M) {
|
|
type InitialProcedureRequest struct {
|
|
Page
|
|
ProjectNo string `json:"project_no"`
|
|
ProjectName string `json:"project_name"`
|
|
ProjectUnit *int `json:"project_unit"`
|
|
InvestType *int `json:"invest_type"`
|
|
}
|
|
type InitialProcedureResponse struct {
|
|
InitiationTime time.Time `json:"initiation_time"`
|
|
ProjectNo string `json:"project_no"`
|
|
ProjectName string `json:"project_name"`
|
|
ProjectUnit string `json:"project_unit"`
|
|
ProjectType string `json:"project_type"`
|
|
Allnum int `json:"all_num"`
|
|
NotHandleNum int `json:"not_handle_num"`
|
|
NoHandleNum int `json:"no_handle_num"`
|
|
HandlingNum int `json:"handling_num"`
|
|
HandledNum int `json:"handled_num"`
|
|
}
|
|
var data []InitialProcedureResponse
|
|
project_unit := 1
|
|
sqlb := DefaultSqlBuilder()
|
|
slqs := `select max(t1.establishment_time),max(t1.number),max(t1.name),max(t2.name) as project_unit,max(t3.name) as project_type,
|
|
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
|
|
left join tcompany t2 on t1.investor_id = t2.autoseq and t2.del = 0
|
|
left join tinvestment_type t3 on t1.industry_category_id = t3.autoseq and t3.del = 0
|
|
left join tinvestment_type_bind_procedure t4 on t3.autoseq = t4.investment_type_id and t4.del = 0
|
|
left join tprocedure t5 on t4.procedure_id = t5.autoseq and t5.del = 0 @c
|
|
left join tpreliminary_procedures t6 on t5.autoseq = t6.procedures_id
|
|
where t1.del = 0 @c @c @c @c
|
|
group by t1.autoseq`
|
|
sqlb.Sql = slqs
|
|
sqlb.Conditions("t5.type = ?", 1)
|
|
if project_unit != 1 {
|
|
sqlb.Conditions("t2.autoseq = ?", project_unit)
|
|
}
|
|
var err error
|
|
var page Page
|
|
page.Data = &data
|
|
err = sqlb.PaginateBySql(page.Data, &page)
|
|
fmt.Println(err, page.Data)
|
|
}
|