|
|
package models
|
|
|
|
|
|
import (
|
|
|
"bytes"
|
|
|
"fmt"
|
|
|
"opp/internal/utils"
|
|
|
"time"
|
...
|
...
|
@@ -16,7 +17,7 @@ type Chance struct { |
|
|
ChanceTypeId int `orm:"column(chance_type_id)" description:"表chance_type.id 机会类型 "`
|
|
|
AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"`
|
|
|
AuditTemplateConfig string `orm:"column(audit_template_config);size(255);null" description:"模板配置 (存旧的配置信息,对新改动的不影响)"`
|
|
|
Content string `orm:"column(content)" description:"格式化后的文本内容"`
|
|
|
//Content string `orm:"column(content)" description:"格式化后的文本内容"`
|
|
|
SourceContent string `orm:"column(source_content)" description:"原始表单内容 json"`
|
|
|
ViewTotal int `orm:"column(view_total)" description:"查看总数"`
|
|
|
CommentTotal int `orm:"column(comment_total)" description:"评论总数"`
|
...
|
...
|
@@ -39,6 +40,8 @@ type Chance struct { |
|
|
CheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"时间"`
|
|
|
CheckResultStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"`
|
|
|
CheckResult string `orm:"column(check_result);null" description:"筛选结果"`
|
|
|
Type int8 `orm:"column(type)" description:"机会类别:0:机会池 1:储备池 "`
|
|
|
ReserveTypeId int `orm:"column(reserve_type_id)" description:"当前审批步骤"`
|
|
|
}
|
|
|
|
|
|
const (
|
...
|
...
|
@@ -46,6 +49,32 @@ const ( |
|
|
ChanceStatusClose = 2 //关闭
|
|
|
)
|
|
|
|
|
|
const (
|
|
|
ChancePool = iota //机会池
|
|
|
ChanceReserve //机会储备池
|
|
|
)
|
|
|
|
|
|
type ChancePoolOption struct {
|
|
|
ChanceTypeId int //机会类型编号
|
|
|
DIds []int //部门编号列表
|
|
|
Type int8 //机会类型
|
|
|
ReserveTypeId int //机会储备类型编号
|
|
|
}
|
|
|
|
|
|
//机会池查询选项
|
|
|
//@chanceTypeId 机会类型编号
|
|
|
//@deps 部门编号列表
|
|
|
//@t 机会类型
|
|
|
//@rt 储备类型
|
|
|
func NewChancePoolOption(chanceTypeId int, deps []int, t int8, rt int) *ChancePoolOption {
|
|
|
return &ChancePoolOption{
|
|
|
ChanceTypeId: chanceTypeId,
|
|
|
DIds: deps,
|
|
|
Type: t,
|
|
|
ReserveTypeId: rt,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
var (
|
|
|
SqlGetChanceSelfChecks = `select user_id,review_status,self_checks from chance where id =?` //机会自查数据
|
|
|
)
|
...
|
...
|
@@ -273,28 +302,28 @@ where user_id =?` |
|
|
}
|
|
|
|
|
|
//type4 查看所有机会
|
|
|
func GetChancePoolAll(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) {
|
|
|
var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
func GetChancePoolAll(uid, cid int64, option *ChancePoolOption, lastId int64, pageSize int, v interface{}) (total int, err error) {
|
|
|
var filter string = getFilterSql(option)
|
|
|
sql := fmt.Sprintf(`select a.*,b.images,speechs,videos
|
|
|
from (
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
|
|
|
where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1 %v
|
|
|
where company_id=? and review_status=3 and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1 %v
|
|
|
) a left JOIN chance_data b on a.id =b.chance_id
|
|
|
order by create_at desc
|
|
|
limit ?
|
|
|
`, filterDepartment)
|
|
|
`, filter)
|
|
|
|
|
|
//if public==protocol.pu
|
|
|
|
|
|
sqlCount := fmt.Sprintf(`select count(0) from (
|
|
|
select id from chance
|
|
|
where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1 %v
|
|
|
) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId, filterDepartment)
|
|
|
where company_id=? and review_status=3 and enable_status=1 and status=1 %v
|
|
|
) a left JOIN chance_data b on a.id =b.chance_id`, filter)
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {
|
|
|
return
|
|
|
}
|
|
|
if v != nil {
|
|
|
if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil {
|
|
|
if err = utils.ExecuteQueryAll(v, sql, cid, lastId, lastId, pageSize); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -302,61 +331,61 @@ where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and ena |
|
|
}
|
|
|
|
|
|
//type3 特定部门机会
|
|
|
func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
|
|
|
var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
func GetChancePoolSpecialDepartment(uid, cid int64, option *ChancePoolOption, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
|
|
|
var filter string = getFilterSql(option)
|
|
|
sql := fmt.Sprintf(`
|
|
|
select a.*,b.images,speechs,videos from (
|
|
|
select * from (
|
|
|
##公司公开的机会
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where company_id = %v and publish_status = 2 and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##指定部门-机会提交的部门
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where department_id in (%v) and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##本人
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a where review_status=3 and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a left JOIN chance_data b on a.id =b.chance_id
|
|
|
order by create_at desc
|
|
|
limit %v
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, lastId, lastId, filter, pageSize)
|
|
|
|
|
|
sqlCount := fmt.Sprintf(`
|
|
|
select count(0) from (
|
|
|
##公司公开的机会
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where company_id = %v and publish_status = 2 and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##指定部门-机会提交的部门
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where department_id in (%v) and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##本人
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
|
|
|
) a where review_status=3 and a.enable_status=1 and status=1 %v
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, filter)
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -369,13 +398,13 @@ select count(0) from ( |
|
|
}
|
|
|
|
|
|
//type32 特定部门机会 - 多角色时包含levl2 部门公开
|
|
|
func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) {
|
|
|
var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
func GetChancePoolDepartment(uid, cid int64, option *ChancePoolOption, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) {
|
|
|
var filter string = getFilterSql(option)
|
|
|
sql := fmt.Sprintf(`
|
|
|
select a.*,b.images,speechs,videos from (
|
|
|
select * from (
|
|
|
##指定部门-机会公开的部门
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from chance_department where department_id in (%v)
|
|
|
)a inner join chance b on a.chance_id = b.id
|
|
|
where review_status=3
|
...
|
...
|
@@ -383,35 +412,35 @@ select * from ( |
|
|
UNION
|
|
|
|
|
|
##公司公开的机会
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where company_id = %v and publish_status = 2 and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##指定部门-机会提交的部门
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where department_id in (%v) and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##本人
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a where review_status=3 and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a left JOIN chance_data b on a.id =b.chance_id
|
|
|
order by create_at desc
|
|
|
limit %v
|
|
|
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
|
|
|
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, lastId, lastId, filter, pageSize)
|
|
|
|
|
|
sqlCount := fmt.Sprintf(`
|
|
|
select count(0) from (
|
|
|
##指定部门-机会公开的部门
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from chance_department where department_id in (%v)
|
|
|
)a inner join chance b on a.chance_id = b.id
|
|
|
where review_status=3
|
...
|
...
|
@@ -419,27 +448,27 @@ select count(0) from ( |
|
|
UNION
|
|
|
|
|
|
##公司公开的机会
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where company_id = %v and publish_status = 2 and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##指定部门-机会提交的部门
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where department_id in (%v) and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##本人
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
|
|
|
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
|
|
|
) a where review_status=3 and a.enable_status=1 and status=1 %v
|
|
|
`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, filter)
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -452,18 +481,18 @@ select count(0) from ( |
|
|
}
|
|
|
|
|
|
//type2 对我所在部门公开的机会 公司公开的机会
|
|
|
func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
|
|
|
var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
func GetChancePoolPublicCompany(uid, cid int64, option *ChancePoolOption, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
|
|
|
var filter string = getFilterSql(option)
|
|
|
sql := fmt.Sprintf(`
|
|
|
select a.*,b.images,speechs,videos from (
|
|
|
select * from (
|
|
|
##公司公开的机会
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where company_id = %v and publish_status = 2 and review_status=3
|
|
|
|
|
|
UNION
|
|
|
##指定部门-机会公开的部门
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from chance_department where department_id in (%v)
|
|
|
)a inner join chance b on a.chance_id = b.id
|
|
|
where review_status=3
|
...
|
...
|
@@ -471,30 +500,30 @@ select * from ( |
|
|
UNION
|
|
|
|
|
|
##本人
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a where review_status=3 and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a left JOIN chance_data b on a.id =b.chance_id
|
|
|
order by create_at desc
|
|
|
limit %v
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, lastId, lastId, filter, pageSize)
|
|
|
|
|
|
sqlCount := fmt.Sprintf(`
|
|
|
select count(0) from (
|
|
|
##公司公开的机会
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where company_id = %v and publish_status = 2 and review_status=3
|
|
|
|
|
|
UNION
|
|
|
##指定部门-机会公开的部门
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from chance_department where department_id in (%v)
|
|
|
)a inner join chance b on a.chance_id = b.id
|
|
|
where review_status=3
|
...
|
...
|
@@ -502,17 +531,17 @@ select count(0) from ( |
|
|
UNION
|
|
|
|
|
|
##本人
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
|
|
|
) a where review_status=3 and a.enable_status=1 and status=1 %v
|
|
|
`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, filter)
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -530,42 +559,57 @@ func getFilterSqlByDIds(dIds []int) string { |
|
|
return fmt.Sprintf(" and department_id in(%v) ", utils.JoinInts(dIds, ","))
|
|
|
}
|
|
|
|
|
|
func getFilterSql(option *ChancePoolOption) string {
|
|
|
var rsp *bytes.Buffer = bytes.NewBuffer(nil)
|
|
|
rsp.WriteString(fmt.Sprintf(" and type =%v ", option.Type))
|
|
|
if option.ChanceTypeId > 0 {
|
|
|
rsp.WriteString(fmt.Sprintf(" and chance_type_id =%v ", option.ChanceTypeId))
|
|
|
}
|
|
|
if len(option.DIds) > 0 {
|
|
|
rsp.WriteString(fmt.Sprintf(" and department_id in(%v) ", utils.JoinInts(option.DIds, ",")))
|
|
|
}
|
|
|
if option.ReserveTypeId > 0 {
|
|
|
rsp.WriteString(fmt.Sprintf(" and reserve_type_id =%v ", option.ReserveTypeId))
|
|
|
}
|
|
|
return rsp.String()
|
|
|
}
|
|
|
|
|
|
//type1 禁止查看所有机会
|
|
|
func GetChancePoolMyself(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) {
|
|
|
var filterDepartment string = getFilterSqlByDIds(dIds)
|
|
|
func GetChancePoolMyself(uid, cid int64, option *ChancePoolOption, lastId int64, pageSize int, v interface{}) (total int, err error) {
|
|
|
var filter string = getFilterSql(option) // getFilterSqlByDIds(dIds)
|
|
|
sql := fmt.Sprintf(`
|
|
|
select a.*,b.images,speechs,videos from (
|
|
|
select * from (
|
|
|
##本人
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a where review_status=3 and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v
|
|
|
) a left JOIN chance_data b on a.id =b.chance_id
|
|
|
order by create_at desc
|
|
|
limit %v
|
|
|
`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize)
|
|
|
`, uid, uid, lastId, lastId, filter, pageSize)
|
|
|
|
|
|
sqlCount := fmt.Sprintf(`
|
|
|
select count(0) from (
|
|
|
##本人
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from chance
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from chance
|
|
|
where user_id = %v and review_status=3
|
|
|
UNION
|
|
|
|
|
|
##我审核
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status from (
|
|
|
select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,enable_status,department_id,status,type,reserve_type_id from (
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v
|
|
|
) a inner join chance b on a.chance_id = b.id
|
|
|
|
|
|
) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v
|
|
|
`, uid, uid, chanceTypeId, chanceTypeId, filterDepartment)
|
|
|
) a where review_status=3 and a.enable_status=1 and status=1 %v
|
|
|
`, uid, uid, filter)
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -577,62 +621,6 @@ select count(0) from ( |
|
|
return
|
|
|
}
|
|
|
|
|
|
//type4 查看所有机会
|
|
|
func ValidChanceAll(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
|
|
|
|
|
|
// sql := `select a.*,b.images,speechs,videos
|
|
|
//from (
|
|
|
//select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
|
|
|
//where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id<?) and enable_status=1
|
|
|
//order by create_at desc
|
|
|
//limit ?
|
|
|
//) a left JOIN chance_data b on a.id =b.chance_id`
|
|
|
// //if public==protocol.pu
|
|
|
//
|
|
|
// sqlCount := fmt.Sprintf(`select count(0) from (
|
|
|
//select id from chance
|
|
|
//where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1
|
|
|
//order by create_at desc
|
|
|
//) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId)
|
|
|
// if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {
|
|
|
// return
|
|
|
// }
|
|
|
// if v != nil {
|
|
|
// if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil {
|
|
|
// return
|
|
|
// }
|
|
|
// }
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//type3 特定部门机会
|
|
|
func ValidChanceSpecialDepartment(uid, chanceIds string, v interface{}) (err error) {
|
|
|
|
|
|
sql := fmt.Sprintf(`
|
|
|
select * from (
|
|
|
##指定部门-机会提交的部门
|
|
|
##select chance_id from chance
|
|
|
##where id in (v) and department_id in (v)
|
|
|
##UNION
|
|
|
|
|
|
##本人
|
|
|
##select chance_id from chance
|
|
|
##where user_id = v and id in (v)
|
|
|
##UNION
|
|
|
|
|
|
##我审核
|
|
|
select DISTINCT chance_id from audit_flow_process where uid =%v and chance_id in (%v)
|
|
|
)
|
|
|
`, chanceIds)
|
|
|
|
|
|
if v != nil {
|
|
|
if err = utils.ExecuteQueryAll(v, sql); err != nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//是否存在按发布机会部门编号查询
|
|
|
func ExitsChanceByDeparmentIds(chanceId int64, departmentIds []int64) (v *Chance, err error) {
|
|
|
sql := fmt.Sprintf(`select id from chance where id=%v and department_id in (%v)`,
|
...
|
...
|
@@ -696,14 +684,14 @@ func GetSiftingChance(uid int64, submitStatus int, checkResultStatus int, offset |
|
|
from (
|
|
|
select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,b.create_at,
|
|
|
b.view_total,
|
|
|
b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status,b.check_time
|
|
|
b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status,b.check_time,b.type
|
|
|
from (
|
|
|
select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
|
|
|
from audit_flow_process a,(select MAX(id) AS max_id from audit_flow_process as t where t.uid=%v group by chance_id) b
|
|
|
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
|
|
|
GROUP BY chance_id
|
|
|
)a left outer join chance b on a.chance_id = b.id
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status <=%v and length(b.self_checks)>5
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.type=0 and b.check_result_status <=%v and length(b.self_checks)>5
|
|
|
)a left outer join chance_data b on a.chance_id =b.chance_id
|
|
|
%v
|
|
|
limit %v,%v`, uid, uid, submitStatus, checkResultStatus, where, offset, pageSize) //,update_at process_create_time
|
...
|
...
|
@@ -711,14 +699,14 @@ limit %v,%v`, uid, uid, submitStatus, checkResultStatus, where, offset, pageSize |
|
|
sqlCount := fmt.Sprintf(`select count(0)
|
|
|
from (
|
|
|
select a.*,b.user_id chance_user_id,b.source_content,b.enable_status,b.review_status,b.create_at,
|
|
|
b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status
|
|
|
b.update_at,b.approve_time chance_approve_time,b.status,b.self_checks,b.check_result_status,b.type
|
|
|
from (
|
|
|
select max(id) id,approve_time,approve_data,uid,chance_id,submit_check_status,submit_check_time,level
|
|
|
from audit_flow_process a,(select MAX(id) AS max_id from audit_flow_process as t where t.uid=%v group by chance_id) b
|
|
|
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
|
|
|
GROUP BY chance_id
|
|
|
)a left outer join chance b on a.chance_id = b.id
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status <=%v and length(b.self_checks)>5
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.type=0 and b.check_result_status <=%v and length(b.self_checks)>5
|
|
|
)a
|
|
|
`, uid, uid, submitStatus, checkResultStatus) //and enable_status =1
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
...
|
...
|
@@ -747,7 +735,7 @@ from ( |
|
|
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
|
|
|
GROUP BY chance_id
|
|
|
)a left outer join chance b on a.chance_id = b.id
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status =%v
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.type=0 and b.check_result_status =%v
|
|
|
)a left outer join chance_data b on a.chance_id =b.chance_id
|
|
|
order by a.check_time desc
|
|
|
limit %v,%v`, uid, uid, submitStatus, checkResultStatus, offset, pageSize) //,update_at process_create_time
|
...
|
...
|
@@ -762,7 +750,7 @@ from ( |
|
|
where a.uid=%v and b.max_id=a.id and a.submit_check_status=%v and level>0
|
|
|
GROUP BY chance_id
|
|
|
)a left outer join chance b on a.chance_id = b.id
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.check_result_status =%v
|
|
|
where b.review_status=3 and b.enable_status=1 and b.status=1 and b.type=0 and b.check_result_status =%v
|
|
|
)a
|
|
|
`, uid, uid, submitStatus, checkResultStatus) //and enable_status =1
|
|
|
if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
|
...
|
...
|
|