participateStatistics.go 38 KB

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