participateStatistics.go 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/date"
  5. "app.yhyue.com/moapp/jybase/encrypt"
  6. "app.yhyue.com/moapp/jybase/redis"
  7. "encoding/json"
  8. "fmt"
  9. "jyBXCore/rpc/bxcore"
  10. IC "jyBXCore/rpc/init"
  11. "jyBXCore/rpc/model/es"
  12. "log"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. const (
  18. //角色
  19. Role_admin_system = 1 //系统管理员
  20. Role_admin_department = 2 //部门管理员
  21. )
  22. type ParticipateStatistics struct {
  23. PositionId int64
  24. EntId int64
  25. DeptId int64
  26. EntUserId int64
  27. }
  28. func (in *ParticipateStatistics) PushStatistics(entUserIdArr []string, startTime, endTime int64, source []int64) (result []*bxcore.PushStatisticsData) {
  29. //判断是企业、部门还是个人
  30. isAdmin, personArrStr, users, userInfo := in.PersonHandle(entUserIdArr)
  31. //时间处理
  32. query := QueryHandle(isAdmin, startTime, endTime, personArrStr, source, 0)
  33. //推送数据查询
  34. dataList := IC.BaseMysql.SelectBySql(fmt.Sprintf("select * from participate_push_statistics where %s order by ymd", strings.Join(query, " and ")))
  35. isManage := false
  36. if users != nil && len(*users) > 0 {
  37. if userInfo != nil {
  38. isManage = userInfo.Role_admin_department || userInfo.Role_admin_system
  39. }
  40. result = PushHandle(dataList, users, isAdmin, isManage)
  41. }
  42. return
  43. }
  44. func (in *ParticipateStatistics) ProjectStatistics(entUserIdArr []string, startTime, endTime, bidWay int64) (result []*bxcore.ProjectStatisticsData) {
  45. //判断是企业、部门还是个人
  46. isAdmin, personArrStr, users, _ := in.PersonHandle(entUserIdArr)
  47. query := QueryHandle(isAdmin, startTime, endTime, personArrStr, []int64{}, bidWay)
  48. //订阅推送数处理
  49. //推送数据查询
  50. dataList := IC.BaseMysql.SelectBySql(fmt.Sprintf("select * from participate_project_statistics where %s order by ymd ", strings.Join(query, "and ")))
  51. if users != nil && len(*users) > 0 {
  52. result = ProjectHandle(dataList, users, isAdmin, bidWay)
  53. }
  54. return
  55. }
  56. var (
  57. SourceMap = map[string]string{
  58. "1": "个人订阅",
  59. "2": "企业自动分发",
  60. "3": "企业手动分发",
  61. }
  62. )
  63. // GetSourceItem 获取标讯项目来源筛选项
  64. func (in *ParticipateStatistics) GetSourceItem(entId, positionId int) (result []*bxcore.SourceItem) {
  65. redisKey := "sourceItem%s_%d"
  66. query := "select group_concat(distinct(source)) as `source` from participate_push_statistics where "
  67. // 个人用户
  68. if entId == 0 {
  69. // 查职位id
  70. query += fmt.Sprintf(" position_id =%d", positionId)
  71. redisKey = fmt.Sprintf(redisKey, "personal", positionId)
  72. } else {
  73. // 企业用户 用企业id查
  74. query += fmt.Sprintf(" ent_id =%d", entId)
  75. redisKey = fmt.Sprintf(redisKey, "ent", entId)
  76. }
  77. if data, err := redis.GetBytes("other", redisKey); err == nil && data != nil {
  78. err := json.Unmarshal(*data, &result)
  79. if err == nil {
  80. return
  81. } else {
  82. log.Println("序列化失败", redisKey, err)
  83. }
  84. }
  85. rs := IC.BaseMysql.SelectBySql(query)
  86. if rs == nil || len(*rs) == 0 {
  87. //emtpy := make([]*bxcore.SourceItem, 0)
  88. return
  89. }
  90. existMap := map[string]struct{}{}
  91. source_ := common.InterfaceToStr((*rs)[0]["source"])
  92. splitSource := strings.Split(source_, ",")
  93. for i := 0; i < len(splitSource); i++ {
  94. value := splitSource[i]
  95. if value == "" {
  96. continue
  97. }
  98. if _, ok := existMap[value]; ok {
  99. continue
  100. } else {
  101. existMap[value] = struct{}{}
  102. }
  103. if name, ok := SourceMap[value]; ok {
  104. value_, err := strconv.Atoi(value)
  105. if err == nil {
  106. result = append(result, &bxcore.SourceItem{
  107. Name: name,
  108. Value: int64(value_),
  109. })
  110. } else {
  111. log.Println("转换失败:", err, value)
  112. }
  113. }
  114. }
  115. if len(result) > 0 {
  116. // 存缓存
  117. rsByte, _ := json.Marshal(result)
  118. redis.PutBytes("other", redisKey, &rsByte, 60*60*2)
  119. }
  120. return
  121. }
  122. // 注意:该方法返回值中第一个虽然名字叫IsAdmin 但是实际是指是否是企业版 用于区分企业和个人版 不能用于是否是管理员
  123. func (in *ParticipateStatistics) PersonHandle(entUserIdArr []string) (isAdmin bool, idStr string, users *[]map[string]interface{}, userEnt *CurrentUser) {
  124. userEnt = EntInfo(common.IntAll(in.EntId), common.IntAll(in.EntUserId))
  125. if len(entUserIdArr) > 0 {
  126. //查询所选人的部门以及人员信息
  127. users = GetUser(entUserIdArr)
  128. //返回所选人的信息
  129. isAdmin = true
  130. idStr = strings.Join(entUserIdArr, ",")
  131. } else {
  132. if userEnt.Role_admin_department || userEnt.Role_admin_system { //
  133. // 部门管理员 获取所有部门和子部门员工
  134. users = GetDisUsers(common.IntAll(in.EntId), userEnt.Dept.Id)
  135. var staffs []string
  136. if users != nil && len(*users) > 0 {
  137. for _, v := range *users {
  138. staffs = append(staffs, common.InterfaceToStr(v["id"]))
  139. }
  140. }
  141. isAdmin = true
  142. idStr = strings.Join(staffs, ",")
  143. } else {
  144. if userEnt.Dept.Id != 0 {
  145. entUserIdArr = append(entUserIdArr, common.InterfaceToStr(in.EntUserId))
  146. users = GetUser(entUserIdArr)
  147. //返回所选人的信息
  148. isAdmin = true
  149. idStr = strings.Join(entUserIdArr, ",")
  150. } else {
  151. isAdmin = false
  152. idStr = common.InterfaceToStr(in.PositionId)
  153. users = &[]map[string]interface{}{
  154. map[string]interface{}{
  155. "id": in.PositionId,
  156. "name": "个人",
  157. },
  158. }
  159. }
  160. }
  161. }
  162. return
  163. }
  164. type PushData struct {
  165. PersonName string
  166. entUserId string
  167. DepartmentName string
  168. PushNumb map[string]interface{}
  169. ParticipateNumb map[string]interface{}
  170. BidNumb map[string]interface{}
  171. WinNumb map[string]interface{}
  172. BrowseNumb map[string]interface{}
  173. SourceMap map[string]sourceStruct
  174. }
  175. type sourceStruct struct {
  176. PushNumb map[string]interface{}
  177. ParticipateNumb map[string]interface{}
  178. BidNumb map[string]interface{}
  179. WinNumb map[string]interface{}
  180. BrowseNumb map[string]interface{}
  181. }
  182. type ProjectData struct {
  183. PersonName string
  184. DepartmentName string
  185. entUserId string
  186. BidNumb map[string]interface{} //投标数量
  187. DirectBidNumb map[string]interface{} //直接投标数
  188. ChannelBidNumb map[string]interface{} //渠道投标数
  189. WinNumb map[string]interface{}
  190. DirectWinNumb map[string]interface{} //直接中标数
  191. ChannelWinNumb map[string]interface{} //渠道中标数
  192. NotBidNumber map[string]interface{} //未中标数量
  193. EndNumb map[string]interface{} //终止数量
  194. participateProjectNumb map[string]interface{} // 参标数量
  195. Stage map[string]map[string]interface{}
  196. StageStr map[string]string // 字符串处理
  197. EndProject map[string]struct{} // 终止参标项目不参与统计
  198. }
  199. func PushHandle(data *[]map[string]interface{}, users *[]map[string]interface{}, isAdmin bool, isManager bool) []*bxcore.PushStatisticsData {
  200. result := &map[int64]*PushData{}
  201. for k, v := range *users {
  202. (*result)[common.Int64All(v["id"])] = &PushData{
  203. PersonName: fmt.Sprintf("%s_%d", common.InterfaceToStr(v["name"]), k),
  204. DepartmentName: common.InterfaceToStr(v["dept_name"]),
  205. entUserId: common.InterfaceToStr(v["id"]),
  206. }
  207. }
  208. if data != nil && len(*data) > 0 {
  209. for _, v := range *data {
  210. userId := int64(0)
  211. if isAdmin {
  212. userId = common.Int64All(v["ent_user_id"])
  213. } else {
  214. userId = common.Int64All(v["position_id"])
  215. }
  216. if (*result)[userId] != nil {
  217. //浏览总数处理处理
  218. project_id := common.InterfaceToStr(common.InterfaceToStr(v["project_id"]))
  219. if common.Int64All(v["isvisit"]) > 0 {
  220. (*result)[userId].BrowseNumb = DataHanle((*result)[userId].BrowseNumb, project_id)
  221. }
  222. //推送总数处理
  223. (*result)[userId].PushNumb = DataHanle((*result)[userId].PushNumb, project_id)
  224. //参标总数处理
  225. if common.Int64All(v["isparticipate"]) > 0 {
  226. (*result)[userId].ParticipateNumb = DataHanle((*result)[userId].ParticipateNumb, project_id)
  227. }
  228. //投标总数处理
  229. if common.Int64All(v["isbid"]) > 0 {
  230. (*result)[userId].BidNumb = DataHanle((*result)[userId].BidNumb, project_id)
  231. }
  232. //中标总数处理
  233. if common.Int64All(v["win_status"]) != 0 {
  234. win_status := common.Int64All(v["win_status"])
  235. if win_status == 1 {
  236. (*result)[userId].WinNumb = DataHanle((*result)[userId].WinNumb, project_id)
  237. } else {
  238. delete((*result)[userId].WinNumb, project_id)
  239. }
  240. }
  241. // 如果是个人处理 按照source分开统计
  242. if !isManager && common.InterfaceToStr(common.InterfaceToStr(v["source"])) != "" {
  243. splitSource := strings.Split(common.InterfaceToStr(common.InterfaceToStr(v["source"])), ",")
  244. for i := 0; i < len(splitSource); i++ {
  245. //
  246. if (*result)[userId].SourceMap == nil {
  247. (*result)[userId].SourceMap = map[string]sourceStruct{}
  248. }
  249. if _, ok := (*result)[userId].SourceMap[splitSource[i]]; !ok {
  250. (*result)[userId].SourceMap[splitSource[i]] = sourceStruct{}
  251. }
  252. tmp := (*result)[userId].SourceMap[splitSource[i]]
  253. //浏览总数处理处理
  254. if common.Int64All(v["isvisit"]) > 0 {
  255. tmp.BrowseNumb = DataHanle(tmp.BrowseNumb, project_id)
  256. }
  257. //推送总数处理
  258. tmp.PushNumb = DataHanle(tmp.PushNumb, project_id)
  259. //参标总数处理
  260. if common.Int64All(v["isparticipate"]) > 0 {
  261. tmp.ParticipateNumb = DataHanle(tmp.ParticipateNumb, project_id)
  262. }
  263. //投标总数处理
  264. if common.Int64All(v["isbid"]) > 0 {
  265. tmp.BidNumb = DataHanle(tmp.BidNumb, project_id)
  266. }
  267. //中标总数处理
  268. if common.Int64All(v["win_status"]) != 0 {
  269. win_status := common.Int64All(v["win_status"])
  270. if win_status == 1 {
  271. tmp.WinNumb = DataHanle(tmp.WinNumb, project_id)
  272. } else {
  273. delete(tmp.WinNumb, project_id)
  274. }
  275. }
  276. (*result)[userId].SourceMap[splitSource[i]] = tmp
  277. }
  278. }
  279. }
  280. }
  281. }
  282. pushStatisticsList := []*bxcore.PushStatisticsData{}
  283. if !isManager {
  284. for _, v := range *result {
  285. for sourceK, sourceV := range v.SourceMap {
  286. personName := strings.Split(v.PersonName, "_")[0]
  287. pushStatisticsList = append(pushStatisticsList, &bxcore.PushStatisticsData{
  288. PersonName: personName,
  289. DepartmentName: v.DepartmentName,
  290. EntUserId: encrypt.SE.Encode2Hex(v.entUserId),
  291. ParticipateNumb: int64(len(sourceV.ParticipateNumb)),
  292. BrowseNumb: int64(len(sourceV.BrowseNumb)),
  293. BidNumb: int64(len(sourceV.BidNumb)),
  294. WinNumb: int64(len(sourceV.WinNumb)),
  295. PushNumb: int64(len(sourceV.PushNumb)),
  296. Source: common.InterfaceToStr(SourceMap[sourceK]),
  297. })
  298. }
  299. }
  300. } else {
  301. pushStatisticsList = make([]*bxcore.PushStatisticsData, len(*result))
  302. for _, v := range *result {
  303. personName := strings.Split(v.PersonName, "_")[0]
  304. k := common.Int64All(strings.Split(v.PersonName, "_")[1])
  305. pushStatisticsList[k] = &bxcore.PushStatisticsData{
  306. PersonName: personName,
  307. DepartmentName: v.DepartmentName,
  308. EntUserId: encrypt.SE.Encode2Hex(v.entUserId),
  309. PushNumb: common.Int64All(len(v.PushNumb)),
  310. ParticipateNumb: common.Int64All(len(v.ParticipateNumb)),
  311. BidNumb: common.Int64All(len(v.BidNumb)),
  312. WinNumb: common.Int64All(len(v.WinNumb)),
  313. BrowseNumb: common.Int64All(len(v.BrowseNumb)),
  314. }
  315. }
  316. }
  317. return pushStatisticsList
  318. }
  319. var stageNameArr = map[int64][]string{
  320. 1: []string{"已报名", "投标决策", "编织投标文件", "递交投标文件", "中标公示", "签合同", "已结束"},
  321. 2: []string{"已报名", "中标公示", "签合同", "已结束"},
  322. }
  323. func ProjectHandle(data *[]map[string]interface{}, users *[]map[string]interface{}, isAdmin bool, bidWay int64) []*bxcore.ProjectStatisticsData {
  324. result := &map[int64]*ProjectData{}
  325. for k, v := range *users {
  326. (*result)[common.Int64All(v["id"])] = &ProjectData{
  327. PersonName: fmt.Sprintf("%s_%d", common.InterfaceToStr(v["name"]), k),
  328. DepartmentName: common.InterfaceToStr(v["dept_name"]),
  329. entUserId: common.InterfaceToStr(v["id"]),
  330. }
  331. }
  332. if data != nil && len(*data) > 0 {
  333. for _, v := range *data {
  334. userId := int64(0)
  335. if isAdmin {
  336. userId = common.Int64All(v["ent_user_id"])
  337. } else {
  338. userId = common.Int64All(v["position_id"])
  339. }
  340. project_id := common.InterfaceToStr(common.InterfaceToStr(v["project_id"]))
  341. if (*result)[userId] != nil {
  342. stage := common.ObjToString(v["bid_stage"])
  343. if _, ok := (*result)[userId].StageStr[project_id]; !ok {
  344. (*result)[userId].StageStr = map[string]string{}
  345. }
  346. (*result)[userId].StageStr[project_id] = stage
  347. isEnd_ := common.IntAll(v["is_end"])
  348. if isEnd_ == 1 {
  349. // 标记成已结束
  350. (*result)[userId].EndProject[project_id] = struct{}{}
  351. }
  352. }
  353. }
  354. existProject := map[string]struct{}{}
  355. for _, v := range *data {
  356. userId := int64(0)
  357. if isAdmin {
  358. userId = common.Int64All(v["ent_user_id"])
  359. } else {
  360. userId = common.Int64All(v["position_id"])
  361. }
  362. project_id := common.InterfaceToStr(common.InterfaceToStr(v["project_id"]))
  363. if (*result)[userId] != nil {
  364. //终止参保统计
  365. if common.Int64All(v["isend"]) != 0 {
  366. (*result)[userId].EndNumb = DataHanle((*result)[userId].EndNumb, project_id)
  367. }
  368. // 已经终止的不参与统计数量
  369. if _, ok := (*result)[userId].EndProject[project_id]; ok {
  370. continue
  371. }
  372. // 参标数量
  373. (*result)[userId].participateProjectNumb = DataHanle((*result)[userId].participateProjectNumb, project_id)
  374. //投标数量
  375. if common.Int64All(v["isbid"]) > 0 {
  376. (*result)[userId].BidNumb = DataHanle((*result)[userId].BidNumb, project_id)
  377. }
  378. //直接投标数
  379. if common.Int64All(v["bid_way"]) > 0 {
  380. if common.Int64All(v["bid_way"]) == 2 {
  381. (*result)[userId].ChannelBidNumb = DataHanle((*result)[userId].ChannelBidNumb, project_id)
  382. delete((*result)[userId].DirectBidNumb, project_id)
  383. } else {
  384. (*result)[userId].DirectBidNumb = DataHanle((*result)[userId].DirectBidNumb, project_id)
  385. delete((*result)[userId].ChannelBidNumb, project_id)
  386. }
  387. }
  388. //中标总数处理
  389. if common.Int64All(v["win_status"]) != 0 {
  390. if common.Int64All(v["win_status"]) > 0 {
  391. //中标数量
  392. (*result)[userId].WinNumb = DataHanle((*result)[userId].WinNumb, project_id)
  393. delete((*result)[userId].NotBidNumber, project_id)
  394. } else {
  395. //未中标数量
  396. (*result)[userId].NotBidNumber = DataHanle((*result)[userId].NotBidNumber, project_id)
  397. delete((*result)[userId].WinNumb, project_id)
  398. }
  399. }
  400. //中标方式处理
  401. if common.Int64All(v["win_bidway"]) != 0 {
  402. if common.Int64All(v["win_bidway"]) == 1 {
  403. //直接投标数量
  404. (*result)[userId].DirectWinNumb = DataHanle((*result)[userId].DirectWinNumb, project_id)
  405. delete((*result)[userId].ChannelWinNumb, project_id)
  406. } else {
  407. //渠道投标数量
  408. (*result)[userId].ChannelWinNumb = DataHanle((*result)[userId].ChannelWinNumb, project_id)
  409. delete((*result)[userId].DirectWinNumb, project_id)
  410. }
  411. }
  412. if bidWay == 0 {
  413. // 投标类型为全部时不需要统计勾选的数量
  414. continue
  415. }
  416. existKey := fmt.Sprintf("%d_%s", userId, project_id)
  417. if _, ok := existProject[existKey]; !ok {
  418. existProject[existKey] = struct{}{}
  419. } else {
  420. continue
  421. }
  422. // 阶段勾选数量统计
  423. stage := common.InterfaceToStr((*result)[userId].StageStr[project_id])
  424. if stage != "" {
  425. stageSplit := strings.Split(stage, ",")
  426. if (*result)[userId].Stage == nil {
  427. (*result)[userId].Stage = map[string]map[string]interface{}{}
  428. }
  429. for i := 0; i < len(stageSplit); i++ {
  430. stageK := stageSplit[i]
  431. (*result)[userId].Stage[stageK] = DataHanle((*result)[userId].Stage[stageSplit[i]], project_id)
  432. }
  433. }
  434. }
  435. }
  436. }
  437. projectStatisticsList := make([]*bxcore.ProjectStatisticsData, len(*result))
  438. stageName := []string{}
  439. if bidWay != 0 {
  440. stageName = stageNameArr[bidWay]
  441. }
  442. for _, v := range *result {
  443. personName := strings.Split(v.PersonName, "_")[0]
  444. k := common.Int64All(strings.Split(v.PersonName, "_")[1])
  445. tmpStage := []*bxcore.StageValue{}
  446. if bidWay != 0 && len(stageName) > 0 {
  447. for i := 0; i < len(stageName); i++ {
  448. name_ := fmt.Sprintf("%s(阶段)", stageName[i])
  449. if stageV, ok := v.Stage[stageName[i]]; ok {
  450. tmpStage = append(tmpStage, &bxcore.StageValue{
  451. Name: name_,
  452. Value: fmt.Sprintf("%d", len(stageV)),
  453. })
  454. } else {
  455. tmpStage = append(tmpStage, &bxcore.StageValue{
  456. Name: name_,
  457. Value: "-",
  458. })
  459. }
  460. }
  461. }
  462. projectStatisticsList[k] = &bxcore.ProjectStatisticsData{
  463. PersonName: personName,
  464. DepartmentName: v.DepartmentName,
  465. EntUserId: encrypt.SE.Encode2Hex(v.entUserId),
  466. BidNumb: common.Int64All(len(v.BidNumb)),
  467. DirectBidNumb: common.Int64All(len(v.DirectBidNumb)),
  468. ChannelBidNumb: common.Int64All(len(v.ChannelBidNumb)),
  469. WinNumb: common.Int64All(len(v.WinNumb)),
  470. DirectWinNumb: common.Int64All(len(v.DirectWinNumb)),
  471. ChannelWinNumb: common.Int64All(len(v.ChannelWinNumb)),
  472. NotBidNumber: common.Int64All(len(v.NotBidNumber)),
  473. EndNumb: common.Int64All(len(v.EndNumb)),
  474. ParticipateProjectNumb: common.Int64All(len(v.participateProjectNumb)),
  475. Stage: tmpStage,
  476. }
  477. }
  478. return projectStatisticsList
  479. }
  480. func EntInfo(entId, entUserId int) *CurrentUser {
  481. currentUser := &CurrentUser{
  482. Dept: &Department{},
  483. }
  484. user := IC.MainMysql.SelectBySql(`SELECT a.name as user_name from entniche_user a INNER JOIN entniche_user_role b on (a.id=b.user_id) where a.id=? and b.role_id=? limit 1`, entUserId, Role_admin_system)
  485. if user != nil && len(*user) > 0 {
  486. currentUser.Role_admin_system = true
  487. currentUser.User_name, _ = (*user)[0]["user_name"].(string)
  488. currentUser.User_power = 1
  489. r := IC.MainMysql.SelectBySql(`SELECT id,name,subdis,nodiff from entniche_department where ent_id=? and pid=0 limit 1`, entId)
  490. if r != nil && len(*r) == 1 {
  491. department := JsonUnmarshal((*r)[0], &Department{}).(*Department)
  492. if department != nil {
  493. department.Pid = department.Id
  494. currentUser.Dept = department
  495. }
  496. }
  497. } else {
  498. //角色、权限
  499. r := IC.MainMysql.SelectBySql(`SELECT a.name as user_name,a.power as user_power,b.role_id,d.id as dept_id,d.name as dept_name,d.subdis as dept_subdis,d.nodiff as dept_nodiff,e.id as dept_pid from entniche_user a
  500. LEFT JOIN entniche_user_role b on (b.user_id=?)
  501. INNER JOIN entniche_department_user c on (a.id=? and a.id=c.user_id)
  502. INNER JOIN entniche_department d on (c.dept_id=d.id)
  503. INNER JOIN entniche_department e on (e.ent_id=? and e.pid=0)
  504. order by a.id desc limit 1`, entUserId, entUserId, entId)
  505. if r != nil && len(*r) == 1 {
  506. currentUser.User_name, _ = (*r)[0]["user_name"].(string)
  507. currentUser.User_power = common.IntAll((*r)[0]["user_power"])
  508. if common.IntAll((*r)[0]["role_id"]) == Role_admin_department {
  509. currentUser.Role_admin_department = true
  510. }
  511. currentUser.Dept.Id = common.IntAll((*r)[0]["dept_id"])
  512. currentUser.Dept.Pid = common.IntAll((*r)[0]["dept_pid"])
  513. currentUser.Dept.Name = common.ObjToString((*r)[0]["dept_name"])
  514. currentUser.Dept.Subdis = common.IntAll((*r)[0]["dept_subdis"])
  515. currentUser.Dept.Nodiff = common.IntAll((*r)[0]["dept_nodiff"])
  516. }
  517. }
  518. return currentUser
  519. }
  520. // map转结构体
  521. func JsonUnmarshal(m interface{}, s interface{}) interface{} {
  522. var b []byte
  523. if v, ok := m.(string); ok {
  524. b = []byte(v)
  525. } else if v, ok := m.([]byte); ok {
  526. b = v
  527. } else {
  528. b, _ = json.Marshal(m)
  529. }
  530. json.Unmarshal(b, &s)
  531. return s
  532. }
  533. // 获取部门下可以进行分发的人员(不包含部门名称和部门id)
  534. func GetDisUsers(entId, deptId int) *[]map[string]interface{} {
  535. r := IC.MainMysql.SelectBySql(`select DISTINCT c.id,c.name,c.phone,c.power,b.dept_id,d.name as dept_name
  536. from entniche_department_parent a
  537. INNER JOIN entniche_department_user b on (b.dept_id=? or (a.pid=? and a.id=b.dept_id))
  538. INNER JOIN entniche_user c on (c.ent_id=? and b.user_id=c.id)
  539. INNER JOIN entniche_department d on d.id=b.dept_id
  540. order by b.dept_id , convert(c.name using gbk) COLLATE gbk_chinese_ci asc`, deptId, deptId, entId)
  541. return r
  542. }
  543. func GetUser(entUserIdArr []string) *[]map[string]interface{} {
  544. r := IC.MainMysql.SelectBySql("SELECT DISTINCT a.id, a.name, a.phone, d.id AS dept_id, d.NAME AS dept_name " +
  545. "FROM entniche_user a " +
  546. " INNER JOIN entniche_department_user b ON FIND_IN_SET(a.id,'" + strings.Join(entUserIdArr, ",") +
  547. "') and b.user_id = a.id " +
  548. " INNER JOIN entniche_department d ON d.id = b.dept_id " +
  549. " ORDER BY d.id, CONVERT ( a.NAME USING gbk ) COLLATE gbk_chinese_ci ASC",
  550. )
  551. return r
  552. }
  553. type User struct {
  554. Id int
  555. Name string //员工姓名
  556. Mail string //邮箱
  557. Phone string //手机号
  558. Dept_id int //部门id
  559. Dept_name string //部门名称
  560. //Role string //角色
  561. Power int //权限
  562. }
  563. type CurrentUser struct {
  564. Role_admin_department bool //是否是部门管理员
  565. Role_admin_system bool //是否是系统管理员
  566. Dept *Department //部门信息
  567. BondPhone string //手机号
  568. NickName string //昵称
  569. HeadImageUrl string //头像
  570. PersonalAuth int //个人认证
  571. PersonalAuthReason string //个人认证不通过原因
  572. User_power int //是否分配权限
  573. User_name string //用户姓名
  574. }
  575. type Department struct {
  576. Id int
  577. Name string //部门名
  578. Pid int //上级部门id
  579. Pname string //上级部门名称
  580. Nodiff int //全员无差别接收 0:关闭 1:打开
  581. Subdis int //订阅分发 0:关闭 1:打开
  582. Aid int //管理员id
  583. Aname string //管理员姓名
  584. Rname string //角色名
  585. User_count int //该部门下员工的总数
  586. Dept_count int //该部门下子部门总数
  587. Ent_id int //公司id
  588. }
  589. func DataHanle(data map[string]interface{}, project_id string) map[string]interface{} {
  590. if data == nil {
  591. data = map[string]interface{}{project_id: 1}
  592. } else {
  593. data[project_id] = 1
  594. }
  595. return data
  596. }
  597. func QueryHandle(isAdmin bool, startTime, endTime int64, personArrStr string, source []int64, bidWay int64) []string {
  598. //时间处理
  599. query := []string{}
  600. if isAdmin {
  601. //是管理员
  602. query = append(query, fmt.Sprintf(" ent_user_id in (%s) ", personArrStr))
  603. } else {
  604. //不是管理员
  605. query = append(query, fmt.Sprintf(" position_id = %s ", personArrStr))
  606. }
  607. if startTime == 0 && endTime == 0 {
  608. //没有传时间,默认时间处理
  609. var start = time.Now().AddDate(0, 0, -30)
  610. query = append(query, fmt.Sprintf(" ymd >= %s ", start.Format("20060102")))
  611. }
  612. if startTime != 0 {
  613. query = append(query, fmt.Sprintf(" ymd >= %d ", startTime))
  614. }
  615. if endTime != 0 {
  616. query = append(query, fmt.Sprintf(" ymd <= %d ", endTime))
  617. }
  618. if len(source) > 0 {
  619. sourceArr := []string{}
  620. for i := 0; i < len(source); i++ {
  621. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', source)", source[i]))
  622. }
  623. query = append(query, fmt.Sprintf(" (%s) ", strings.Join(sourceArr, " or ")))
  624. }
  625. if bidWay != 0 {
  626. query = append(query, fmt.Sprintf("bid_way = %d", bidWay))
  627. }
  628. return query
  629. }
  630. func (in *ParticipateStatistics) ProjectDetails(entUserIdArr []string, detailReq *bxcore.ProjectDetailsReq) (result bxcore.DetailData) {
  631. //判断是企业、还是个人
  632. isEnt, personArrStr, _, _ := in.PersonHandle(entUserIdArr)
  633. queryType := GetQueryType(detailReq)
  634. query, countQuery := GetDetailQuery(isEnt, personArrStr, detailReq, queryType)
  635. totalCount := IC.BaseMysql.CountBySql(countQuery)
  636. if totalCount <= 0 {
  637. return
  638. }
  639. // 处理数据 这里只是筛选出项目id和阶段信息
  640. dataList := IC.BaseMysql.SelectBySql(query)
  641. if dataList == nil || len(*dataList) == 0 {
  642. return
  643. }
  644. // 处理数据 补充项目名称、推送表字段 、格式化数据
  645. rs := ProjectDetailHandle(*dataList, in.EntId, int(detailReq.PositionId), int(detailReq.PositionType))
  646. result = bxcore.DetailData{
  647. List: rs,
  648. Total: totalCount,
  649. }
  650. // 处理数据
  651. return
  652. }
  653. // 这个查询只用查出符合筛选条件的项目id 以及该项目对应的stage
  654. // 查询类型 0空搜索 全连接 1查左边 连右表查stage 2只查右表 3内连接
  655. func GetDetailQuery(isEnt bool, personArrStr string, req *bxcore.ProjectDetailsReq, queryType int) (string, string) {
  656. // 处理分页
  657. if req.PageNum == 0 || req.PageSize == 0 {
  658. req.PageNum = 1
  659. req.PageSize = 50
  660. }
  661. // 这是因为数据库中 0是未参标 1是已参标, 接收参数时和其他默认参数保持一致 0-全部 1 是未参标 2 是已参标
  662. req.IsParticipate -= 1
  663. if queryType == 0 {
  664. // 空搜索调整
  665. query1, query2 := []string{}, []string{}
  666. query3 := ""
  667. //没有传时间,默认时间处理
  668. var start = time.Now().AddDate(0, 0, -10)
  669. query1 = append(query1, fmt.Sprintf(" a.ymd >= %s ", start.Local().Format("20060102")))
  670. query2 = append(query2, fmt.Sprintf(" b.update_date >= '%s' ", start.Local().Format(date.Date_Full_Layout)))
  671. if isEnt {
  672. //是企业版
  673. query1 = append(query1, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
  674. personArr := []string{}
  675. personArrStrSplit := strings.Split(personArrStr, ",")
  676. for i := 0; i < len(personArrStrSplit); i++ {
  677. personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.ent_user_ids)", personArrStrSplit[i]))
  678. }
  679. if len(personArr) > 0 {
  680. personStr := strings.Join(personArr, " or ")
  681. query2 = append(query2, fmt.Sprintf(" (%s)", personStr))
  682. }
  683. query3 = fmt.Sprintf("b.ent_id='%d'", req.EntId) // 连接时右表的条件
  684. } else {
  685. //不是企业版
  686. query1 = append(query1, fmt.Sprintf(" a.position_id = %s ", personArrStr))
  687. personArr := []string{}
  688. personArrStrSplit := strings.Split(personArrStr, ",")
  689. for i := 0; i < len(personArrStrSplit); i++ {
  690. personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.position_ids)", personArrStrSplit[i]))
  691. }
  692. if len(personArr) > 0 {
  693. personStr := strings.Join(personArr, " or ")
  694. query2 = append(query2, fmt.Sprintf(" (%s)", personStr))
  695. }
  696. query3 = fmt.Sprintf("b.position_ids='%d'", req.PositionId) // 连接时右表的条件
  697. }
  698. q := `SELECT A.project_id, B.stage
  699. FROM
  700. (SELECT DISTINCT(project_id)
  701. FROM
  702. (SELECT project_id FROM participate_push_statistics a
  703. WHERE %s UNION
  704. SELECT project_id
  705. FROM participate_stage_statistics b
  706. WHERE %s) order by project_id
  707. LIMIT %d , %d) A
  708. LEFT JOIN
  709. participate_stage_statistics B ON A.project_id = B.project_id and %s` // and 连接前对右表过滤
  710. q2 := "select count(project_id) from (select distinct(project_id) from participate_push_statistics a where %s union select project_id from participate_stage_statistics b where %s )"
  711. q1Str := strings.Join(query1, " and ")
  712. q2Str := strings.Join(query2, " and ")
  713. return fmt.Sprintf(q, q1Str, q2Str, (req.PageNum-1)*req.PageSize, req.PageSize, query3), fmt.Sprintf(q2, q1Str, q2Str)
  714. }
  715. var q, qCount string
  716. query := []string{}
  717. joinStr := ""
  718. if queryType == 1 {
  719. if isEnt {
  720. //是企业版
  721. query = append(query, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
  722. joinStr = "and a.ent_id = b.ent_id"
  723. } else {
  724. query = append(query, fmt.Sprintf(" a.position_id = %s ", personArrStr))
  725. //不是企业版
  726. joinStr = "and a.position_id = b.position_ids"
  727. }
  728. if req.StartTime == 0 && req.EndTime == 0 {
  729. //没有传时间,默认时间处理
  730. var start = time.Now().AddDate(0, 0, -30)
  731. query = append(query, fmt.Sprintf(" a.ymd >= %s ", start.Local().Format("20060102")))
  732. }
  733. if req.StartTime != 0 {
  734. query = append(query, fmt.Sprintf(" a.ymd >= %d ", req.StartTime))
  735. }
  736. if req.EndTime != 0 {
  737. query = append(query, fmt.Sprintf(" a.ymd <= %d ", req.EndTime))
  738. }
  739. // 标讯/项目来源
  740. if len(req.Source) > 0 {
  741. sourceArr := []string{}
  742. for i := 0; i < len(req.Source); i++ {
  743. if req.Source[i] == 0 {
  744. sourceArr = append(sourceArr, "NOT FIND_IN_SET('3', a.source)")
  745. } else {
  746. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", req.Source[i]))
  747. }
  748. }
  749. query = append(query, fmt.Sprintf(" (%s) ", strings.Join(sourceArr, " or ")))
  750. }
  751. //参标状态:-1全部,0未参标、1已参标
  752. if req.IsParticipate != -1 {
  753. query = append(query, " (b.project_id is null or b.is_participate=0)")
  754. }
  755. q = "select distinct(a.project_id),b.stage,a.ymd,b.update_date from participate_push_statistics a left join participate_stage_statistics b on(a.project_id=b.project_id %s ) where %s order by a.ymd desc,b.update_date desc"
  756. qCount = "select count(distinct(a.project_id)) from participate_push_statistics a left join participate_stage_statistics b on(a.project_id=b.project_id %s) where %s"
  757. } else if queryType == 2 {
  758. if isEnt {
  759. //是企业版
  760. personArr := []string{}
  761. personArrStrSplit := strings.Split(personArrStr, ",")
  762. for i := 0; i < len(personArrStrSplit); i++ {
  763. personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.ent_user_ids)", personArrStrSplit[i]))
  764. }
  765. if len(personArr) > 0 {
  766. personStr := strings.Join(personArr, " or ")
  767. query = append(query, fmt.Sprintf("(%s)", personStr))
  768. }
  769. } else {
  770. //不是企业版
  771. query = append(query, fmt.Sprintf(" FIND_IN_SET('%s', b.position_ids)", personArrStr))
  772. }
  773. //// 无默认时间时
  774. if req.BidUpdateStartTime == 0 && req.BidUpdateEndTime == 0 {
  775. var start = time.Now().AddDate(0, 0, -30)
  776. query = append(query, fmt.Sprintf(" b.update_date >= '%s' ", start.Local().Format(date.Date_Full_Layout)))
  777. }
  778. // 参标状态更新时间
  779. if req.BidUpdateStartTime != 0 {
  780. bidStart_, err := time.ParseInLocation(date.Date_yyyyMMdd, fmt.Sprintf("%d", req.BidUpdateStartTime), time.Local)
  781. if err != nil {
  782. bidStart_ = time.Now().AddDate(0, 0, -30)
  783. log.Println("时间转换失败,使用默认值:", err)
  784. }
  785. bidStart := date.FormatDate(&bidStart_, date.Date_Full_Layout)
  786. query = append(query, fmt.Sprintf("b.update_date >= '%s'", bidStart))
  787. }
  788. if req.BidUpdateEndTime != 0 {
  789. bidEnd_, err := time.ParseInLocation("20060102 15:04:05", fmt.Sprintf("%d 23:59:59", req.BidUpdateEndTime), time.Local)
  790. if err != nil {
  791. bidEnd_ = time.Now().AddDate(0, 0, -30)
  792. log.Println("时间转换失败,使用默认值:", err)
  793. }
  794. bidEnd := date.FormatDate(&bidEnd_, date.Date_Full_Layout)
  795. query = append(query, fmt.Sprintf("b.update_date <= '%s'", bidEnd))
  796. }
  797. if req.BidWay != 0 {
  798. query = append(query, fmt.Sprintf("b.bid_way = %d", req.BidWay))
  799. }
  800. //参标状态:-1全部,0未参标、1已参标
  801. if req.IsParticipate == 1 {
  802. query = append(query, fmt.Sprintf("b.is_participate = %d", req.IsParticipate))
  803. }
  804. q = "select b.project_id,b.stage from participate_stage_statistics b where %s %s order by b.update_date desc"
  805. qCount = "select count(b.project_id) from participate_stage_statistics b where %s %s"
  806. } else {
  807. if isEnt {
  808. //是企业版
  809. query = append(query, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
  810. joinStr = "and a.ent_id = b.ent_id"
  811. } else {
  812. query = append(query, fmt.Sprintf(" a.position_id = %s ", personArrStr))
  813. //不是企业版
  814. // 个人版
  815. joinStr = "and a.position_id = b.position_ids"
  816. }
  817. if req.StartTime != 0 && req.EndTime == 0 && req.BidUpdateStartTime == 0 && req.BidUpdateEndTime == 0 {
  818. var start = time.Now().AddDate(0, 0, -30)
  819. query = append(query, fmt.Sprintf(" a.ymd >= %s ", start.Local().Format("20060102")))
  820. }
  821. if req.StartTime != 0 {
  822. query = append(query, fmt.Sprintf(" a.ymd >= %d ", req.StartTime))
  823. }
  824. if req.EndTime != 0 {
  825. query = append(query, fmt.Sprintf(" a.ymd <= %d ", req.EndTime))
  826. }
  827. if len(req.Source) > 0 {
  828. sourceArr := []string{}
  829. for i := 0; i < len(req.Source); i++ {
  830. if req.Source[i] == 0 {
  831. sourceArr = append(sourceArr, "NOT FIND_IN_SET('3', a.source)")
  832. } else {
  833. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", req.Source[i]))
  834. }
  835. }
  836. query = append(query, fmt.Sprintf(" (%s) ", strings.Join(sourceArr, " or ")))
  837. }
  838. //参标状态:-1全部,0未参标、1已参标
  839. if req.IsParticipate != -1 {
  840. query = append(query, fmt.Sprintf("a.isparticipate = %d", req.IsParticipate))
  841. }
  842. // 投标类型 投标方式;1:直接投标 2:渠道投标',
  843. if req.BidWay != 0 {
  844. query = append(query, fmt.Sprintf("b.bid_way = %d", req.BidWay))
  845. }
  846. // 参标状态更新时间
  847. if req.BidUpdateStartTime != 0 {
  848. bidStart_, err := time.ParseInLocation(date.Date_yyyyMMdd, fmt.Sprintf("%d", req.BidUpdateStartTime), time.Local)
  849. if err != nil {
  850. bidStart_ = time.Now().AddDate(0, 0, -30)
  851. log.Println("时间转换失败,使用默认值:", err)
  852. }
  853. bidStart := date.FormatDate(&bidStart_, date.Date_Full_Layout)
  854. query = append(query, fmt.Sprintf("b.update_date >= '%s'", bidStart))
  855. }
  856. if req.BidUpdateEndTime != 0 {
  857. bidEnd_, err := time.ParseInLocation("20060102 15:04:05", fmt.Sprintf("%d 23:59:59", req.BidUpdateEndTime), time.Local)
  858. if err != nil {
  859. bidEnd_ = time.Now().AddDate(0, 0, -30)
  860. log.Println("时间转换失败,使用默认值:", err)
  861. }
  862. bidEnd := date.FormatDate(&bidEnd_, date.Date_Full_Layout)
  863. query = append(query, fmt.Sprintf("b.update_date <= '%s'", bidEnd))
  864. }
  865. q = "select distinct(a.project_id),b.stage,a.ymd,b.update_date from participate_push_statistics a inner join participate_stage_statistics b on(b.project_id=a.project_id %s) where %s order by a.ymd desc,b.update_date desc"
  866. qCount = "select count(distinct(a.project_id)) from participate_push_statistics a inner join participate_stage_statistics b on(b.project_id=a.project_id %s) where %s"
  867. }
  868. if len(query) > 0 {
  869. q = fmt.Sprintf(q, joinStr, strings.Join(query, " and "))
  870. qCount = fmt.Sprintf(qCount, joinStr, strings.Join(query, " and "))
  871. }
  872. q = fmt.Sprintf("%s limit %d,%d", q, (req.PageNum-1)*req.PageSize, req.PageSize)
  873. return q, qCount
  874. }
  875. type PushInfoStruct struct {
  876. Source string
  877. VisitDate string
  878. DisDate string
  879. IsDistribute int
  880. }
  881. func ProjectDetailHandle(dataList []map[string]interface{}, entId int64, positionId, positionType int) []*bxcore.ProjectDetailData {
  882. //dataList 里面包含 项目id、各阶段信息
  883. // 处理项目名称
  884. projectIdList := []string{}
  885. for i := 0; i < len(dataList); i++ {
  886. projectIdList = append(projectIdList, common.ObjToString(dataList[i]["project_id"]))
  887. }
  888. // 项目名称处理成map用于后续使用
  889. projectNameMap := map[string]string{}
  890. projectNameRs := es.GetProjectNameByProjectId(projectIdList)
  891. if projectNameRs != nil && len(*projectNameRs) > 0 {
  892. for i := 0; i < len(*projectNameRs); i++ {
  893. projectId_ := common.ObjToString((*projectNameRs)[i]["_id"])
  894. projectName_ := (*projectNameRs)[i]["projectname"]
  895. projectNameMap[projectId_] = common.ObjToString(projectName_)
  896. }
  897. }
  898. // 获取推送最新状态
  899. newPushInfo := getNewPushInfo(projectIdList, int(entId), positionId, positionType)
  900. newPushInfoMap := map[string]PushInfoStruct{}
  901. // 处理推送最新状态
  902. if newPushInfo != nil && len(*newPushInfo) > 0 {
  903. for i := 0; i < len(*newPushInfo); i++ {
  904. project_ := common.ObjToString((*newPushInfo)[i]["project_id"])
  905. info := PushInfoStruct{
  906. Source: common.ObjToString((*newPushInfo)[i]["source"]),
  907. VisitDate: common.ObjToString((*newPushInfo)[i]["visit_date"]),
  908. DisDate: common.ObjToString((*newPushInfo)[i]["dis_date"]),
  909. }
  910. newPushInfoMap[project_] = info
  911. }
  912. }
  913. results := []*bxcore.ProjectDetailData{}
  914. // 处理成最后的数据
  915. for i := 0; i < len(dataList); i++ {
  916. projectId := common.ObjToString(dataList[i]["project_id"])
  917. tmp := bxcore.ProjectDetailData{
  918. ProjectName: projectNameMap[projectId],
  919. }
  920. isDistribute_ := ""
  921. // 处理推送表相关字段
  922. if pushInfo_, ok := newPushInfoMap[projectId]; ok {
  923. sourceStr := []string{}
  924. if pushInfo_.Source != "" {
  925. isDistribute_ = "未分发"
  926. sourceSplit := strings.Split(pushInfo_.Source, ",")
  927. for j := 0; j < len(sourceSplit); j++ {
  928. if sourceSplit[j] == "3" {
  929. isDistribute_ = "已分发"
  930. }
  931. if sourceName, ok := SourceMap[sourceSplit[j]]; ok {
  932. sourceStr = append(sourceStr, sourceName)
  933. }
  934. }
  935. }
  936. tmp.Source = strings.Join(sourceStr, ",") // 处理成中文
  937. tmp.ViewDate = pushInfo_.VisitDate
  938. tmp.IsDistribute = isDistribute_
  939. tmp.DisDate = pushInfo_.DisDate
  940. } //
  941. // 处理阶段勾选信息和参标、终止参标信息
  942. if dataList[i]["stage"] != nil {
  943. s := common.ObjToString(dataList[i]["stage"])
  944. err := json.Unmarshal([]byte(strings.Replace(s, "'", "\"", -1)), &tmp.Stage)
  945. if err != nil {
  946. log.Println("stage 反序列失败", err)
  947. }
  948. }
  949. tmp.Id = encrypt.EncodeArticleId2ByCheck(projectId)
  950. results = append(results, &tmp)
  951. }
  952. return results
  953. }
  954. // 获取项目的最新推送状态信息
  955. func getNewPushInfo(projectIds []string, entId int, positionId int, positionType int) *[]map[string]interface{} {
  956. s := ""
  957. if positionType == 0 {
  958. s = fmt.Sprintf("position_id=%d", positionId)
  959. } else {
  960. s = fmt.Sprintf("ent_id=%d", entId)
  961. }
  962. sql := `
  963. SELECT
  964. A.project_id, A.source,DATE_FORMAT(A.visit_date,'%%Y-%%m-%%d') as visit_date, DATE_FORMAT(A.dis_date,'%%Y-%%m-%%d') as dis_date,A.id,A.ymd,B.ymd
  965. FROM participate_push_statistics A inner join (SELECT
  966. project_id,MAX(ymd) as ymd
  967. FROM
  968. participate_push_statistics
  969. WHERE
  970. %s
  971. AND project_id IN ( "` + strings.Join(projectIds, "\",\"") + `" )
  972. GROUP BY project_id) B on (A.project_id=B.project_id and A.ymd=b.ymd) and A.%s
  973. `
  974. query := fmt.Sprintf(sql, s, s)
  975. return IC.BaseMysql.SelectBySql(query)
  976. }
  977. // GetQueryType 查询类型 0空搜索 1查左边 连右表查stage 2只查右表 3内连接
  978. // IsParticipate 接收参数时 0 全部 1 未参标 2已参标 数据库中 未参标是0
  979. func GetQueryType(in *bxcore.ProjectDetailsReq) int {
  980. //
  981. if in.BidUpdateStartTime == 0 && in.BidUpdateEndTime == 0 && in.StartTime == 0 && in.EndTime == 0 && in.IsParticipate == 0 && in.BidWay == 0 && len(in.Source) == 0 {
  982. return 0
  983. }
  984. if in.IsParticipate == 1 {
  985. // 未参标只筛选推送表 右表条件无效
  986. in.BidWay = 0
  987. in.BidUpdateStartTime = 0
  988. in.BidUpdateEndTime = 0
  989. return 1
  990. }
  991. if (in.StartTime != 0 || in.EndTime != 0 || len(in.Source) > 0) && (in.BidUpdateStartTime == 0 && in.BidUpdateEndTime == 0 && in.IsParticipate != 2 && in.BidWay == 0) {
  992. return 1
  993. }
  994. if (in.StartTime == 0 && in.EndTime == 0 && len(in.Source) == 0) && (in.BidUpdateStartTime != 0 || in.BidUpdateEndTime == 0 || in.IsParticipate == 2 || in.BidWay != 0) {
  995. return 2
  996. }
  997. return 3
  998. }