participateStatistics.go 38 KB

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