作者 yangfu

机会池修改

@@ -149,33 +149,6 @@ from audit_flow_process where uid=? and enable_status =1 and review_status in (% @@ -149,33 +149,6 @@ from audit_flow_process where uid=? and enable_status =1 and review_status in (%
149 return 149 return
150 } 150 }
151 151
152 -func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {  
153 -  
154 - sql := `select a.*,b.images,speechs,videos  
155 -from (  
156 -select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance  
157 -where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id<?) and enable_status=1  
158 -order by create_at desc  
159 -limit ?  
160 -) a left JOIN chance_data b on a.id =b.chance_id`  
161 - //if public==protocol.pu  
162 -  
163 - sqlCount := fmt.Sprintf(`select count(0) from (  
164 -select id from chance  
165 -where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1  
166 -order by create_at desc  
167 -) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId)  
168 - if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {  
169 - return  
170 - }  
171 - if v != nil {  
172 - if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil {  
173 - return  
174 - }  
175 - }  
176 - return  
177 -}  
178 -  
179 func GetChanceCollect(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) { 152 func GetChanceCollect(uid int64, lastId int64, pageSize int, v interface{}) (total int, err error) {
180 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from ( 153 sql := fmt.Sprintf(`select a.*,b.images,b.speechs,b.videos from (
181 select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from ( 154 select a.*,b.user_id,b.id,b.create_at,b.source_content,b.enable_status,b.review_status,b.audit_template_id,b.chance_type_id,comment_total,zan_total,view_total from (
@@ -257,3 +230,202 @@ where user_id =?` @@ -257,3 +230,202 @@ where user_id =?`
257 } 230 }
258 return 231 return
259 } 232 }
  233 +
  234 +//type4 查看所有机会
  235 +func GetChancePoolAll(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
  236 +
  237 + sql := `select a.*,b.images,speechs,videos
  238 +from (
  239 +select id,user_id,create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance
  240 +where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or id<?) and enable_status=1
  241 +order by create_at desc
  242 +limit ?
  243 +) a left JOIN chance_data b on a.id =b.chance_id`
  244 + //if public==protocol.pu
  245 +
  246 + sqlCount := fmt.Sprintf(`select count(0) from (
  247 +select id from chance
  248 +where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1
  249 +order by create_at desc
  250 +) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId)
  251 + if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil {
  252 + return
  253 + }
  254 + if v != nil {
  255 + if err = utils.ExecuteQueryAll(v, sql, cid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize); err != nil {
  256 + return
  257 + }
  258 + }
  259 + return
  260 +}
  261 +
  262 +//type3 特定部门机会
  263 +func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
  264 +
  265 + sql := fmt.Sprintf(`
  266 +select a.*,b.images,speechs,videos from (
  267 +select * from (
  268 + ##指定部门-机会提交的部门
  269 + 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 from chance
  270 + where department_id in (%v)
  271 + UNION
  272 +
  273 + ##本人
  274 + 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 from chance
  275 + where user_id = %v
  276 + UNION
  277 +
  278 + ##我审核
  279 + 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 from (
  280 + select DISTINCT chance_id from audit_flow_process where uid =%v
  281 + ) a inner join chance b on a.chance_id = b.id
  282 +
  283 +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or id<%v) and a.enable_status=1
  284 +order by create_at desc
  285 +limit %v
  286 +) a left JOIN chance_data b on a.id =b.chance_id
  287 +`, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
  288 +
  289 + sqlCount := fmt.Sprintf(`
  290 +select count(0) from (
  291 + ##指定部门-机会提交的部门
  292 + 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 from chance
  293 + where department_id in (%v)
  294 + UNION
  295 +
  296 + ##本人
  297 + 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 from chance
  298 + where user_id = %v
  299 + UNION
  300 +
  301 + ##我审核
  302 + 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 from (
  303 + select DISTINCT chance_id from audit_flow_process where uid =%v
  304 + ) a inner join chance b on a.chance_id = b.id
  305 +
  306 +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1
  307 +`, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
  308 + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
  309 + return
  310 + }
  311 + if v != nil {
  312 + if err = utils.ExecuteQueryAll(v, sql); err != nil {
  313 + return
  314 + }
  315 + }
  316 + return
  317 +}
  318 +
  319 +//type2 对我所在部门公开的机会 公司公开的机会
  320 +func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) {
  321 + sql := fmt.Sprintf(`
  322 +select a.*,b.images,speechs,videos from (
  323 +select * from (
  324 + ##公司公开的机会
  325 + 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 from chance
  326 + where company_id = %v and publish_status = 2
  327 +
  328 + UNION
  329 + ##指定部门-机会公开的部门
  330 + 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 from (
  331 + select DISTINCT chance_id from chance_department where department_id in (%v)
  332 + )a inner join chance b on a.chance_id = b.id
  333 + UNION
  334 +
  335 + ##本人
  336 + 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 from chance
  337 + where user_id = %v
  338 + UNION
  339 +
  340 + ##我审核
  341 + 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 from (
  342 + select DISTINCT chance_id from audit_flow_process where uid =%v
  343 + ) a inner join chance b on a.chance_id = b.id
  344 +
  345 +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or id<%v) and a.enable_status=1
  346 +order by create_at desc
  347 +limit %v
  348 +) a left JOIN chance_data b on a.id =b.chance_id
  349 +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
  350 +
  351 + sqlCount := fmt.Sprintf(`
  352 +select count(0) from (
  353 + ##公司公开的机会
  354 + 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 from chance
  355 + where company_id = %v and publish_status = 2
  356 +
  357 + UNION
  358 + ##指定部门-机会公开的部门
  359 + 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 from (
  360 + select DISTINCT chance_id from chance_department where department_id in (%v)
  361 + )a inner join chance b on a.chance_id = b.id
  362 + UNION
  363 +
  364 + ##本人
  365 + 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 from chance
  366 + where user_id = %v
  367 + UNION
  368 +
  369 + ##我审核
  370 + 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 from (
  371 + select DISTINCT chance_id from audit_flow_process where uid =%v
  372 + ) a inner join chance b on a.chance_id = b.id
  373 +
  374 +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1
  375 +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId)
  376 + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
  377 + return
  378 + }
  379 + if v != nil {
  380 + if err = utils.ExecuteQueryAll(v, sql); err != nil {
  381 + return
  382 + }
  383 + }
  384 + return
  385 +}
  386 +
  387 +//type1 禁止查看所有机会
  388 +func GetChancePoolMyself(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
  389 + sql := fmt.Sprintf(`
  390 +select a.*,b.images,speechs,videos from (
  391 +select * from (
  392 + ##本人
  393 + 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 from chance
  394 + where user_id = %v
  395 + UNION
  396 +
  397 + ##我审核
  398 + 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 from (
  399 + select DISTINCT chance_id from audit_flow_process where uid =%v
  400 + ) a inner join chance b on a.chance_id = b.id
  401 +
  402 +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or id<%v) and a.enable_status=1
  403 +order by create_at desc
  404 +limit %v
  405 +) a left JOIN chance_data b on a.id =b.chance_id
  406 +`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize)
  407 +
  408 + sqlCount := fmt.Sprintf(`
  409 +select count(0) from (
  410 + ##本人
  411 + 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 from chance
  412 + where user_id = %v
  413 + UNION
  414 +
  415 + ##我审核
  416 + 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 from (
  417 + select DISTINCT chance_id from audit_flow_process where uid =%v
  418 + ) a inner join chance b on a.chance_id = b.id
  419 +
  420 +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1
  421 +`, uid, uid, chanceTypeId, chanceTypeId)
  422 + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil {
  423 + return
  424 + }
  425 + if v != nil {
  426 + if err = utils.ExecuteQueryAll(v, sql); err != nil {
  427 + return
  428 + }
  429 + }
  430 + return
  431 +}
@@ -87,3 +87,15 @@ where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete @@ -87,3 +87,15 @@ where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete
87 } 87 }
88 return 88 return
89 } 89 }
  90 +
  91 +func GetUserDepartmentIds(id int64, companyId int64, v interface{}) (err error) {
  92 + o := orm.NewOrm()
  93 + sql := `
  94 +select a.department_id
  95 +from user_department a INNER JOIN department b on a.department_id = b.id
  96 +where a.user_company_id =? and a.company_id =? and enable_status =1 and b.delete_at =0`
  97 + if _, err = o.Raw(sql, id, companyId).QueryRows(v); err == nil {
  98 + return
  99 + }
  100 + return
  101 +}
  1 +package agg
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  6 + "opp/models"
  7 +)
  8 +
  9 +//机会池
  10 +func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) {
  11 + var (
  12 + check int
  13 + specialDIds []int64
  14 + userDIds []int64
  15 + )
  16 + if op, e := GetUserPermission(uid); e == nil {
  17 + for i := range op.CheckOption.Departments {
  18 + specialDIds = append(specialDIds, op.CheckOption.Departments[i].Id)
  19 + }
  20 + check = op.Check
  21 + }
  22 + if len(specialDIds) == 0 {
  23 + specialDIds = append(specialDIds, 0)
  24 + }
  25 + log.Debug(fmt.Sprintf("user:%v check:%v", uid, check))
  26 + switch check {
  27 + case OpportunityCheckLv1:
  28 + return models.GetChancePoolMyself(uid, cid, chanceTypeId, lastId, pageSize, v)
  29 + case OpportunityCheckLv2:
  30 + if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil {
  31 + log.Error(err)
  32 + return
  33 + }
  34 + return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds)
  35 + case OpportunityCheckLv3:
  36 + return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds)
  37 + case OpportunityCheckLv4:
  38 + return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
  39 + default:
  40 + return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v)
  41 + }
  42 + return
  43 +}
@@ -1199,7 +1199,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt @@ -1199,7 +1199,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
1199 rsp = &protocol.ChanceStatisticsResponse{} 1199 rsp = &protocol.ChanceStatisticsResponse{}
1200 for i := range chanceType { 1200 for i := range chanceType {
1201 item := chanceType[i] 1201 item := chanceType[i]
1202 - if total, err = models.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil { 1202 + if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil {
1203 log.Error(err) 1203 log.Error(err)
1204 return 1204 return
1205 } 1205 }
@@ -1276,7 +1276,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ @@ -1276,7 +1276,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ
1276 provider *protocol.BaseUserInfo 1276 provider *protocol.BaseUserInfo
1277 flag int 1277 flag int
1278 ) 1278 )
1279 - if total, err = models.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.PageSize, &myChances); err != nil { 1279 + if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.PageSize, &myChances); err != nil {
1280 if err == orm.ErrNoRows { 1280 if err == orm.ErrNoRows {
1281 err = nil 1281 err = nil
1282 return 1282 return
@@ -1849,6 +1849,10 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ @@ -1849,6 +1849,10 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ
1849 rsp.EditScore = op.EditSorce 1849 rsp.EditScore = op.EditSorce
1850 rsp.Check = op.Check 1850 rsp.Check = op.Check
1851 } 1851 }
  1852 + //未设置查看权限
  1853 + if rsp.Check == 0 {
  1854 + rsp.Check = 4
  1855 + }
1852 for i := range op.CheckOption.Departments { 1856 for i := range op.CheckOption.Departments {
1853 rsp.DepartmentIds = append(rsp.DepartmentIds, op.CheckOption.Departments[i].Id) 1857 rsp.DepartmentIds = append(rsp.DepartmentIds, op.CheckOption.Departments[i].Id)
1854 } 1858 }