participateStatistics.go 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", 1))
  719. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", 2))
  720. } else {
  721. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", req.Source[i]))
  722. }
  723. }
  724. query = append(query, fmt.Sprintf(" (%s) ", strings.Join(sourceArr, " or ")))
  725. }
  726. // 投标类型 投标方式;1:直接投标 2:渠道投标',
  727. if req.BidWay != 0 {
  728. query = append(query, fmt.Sprintf("a.bid_way = %d", req.BidWay))
  729. }
  730. //参标状态:-1全部,0未参标、1已参标
  731. if req.IsParticipate != -1 {
  732. query = append(query, fmt.Sprintf("a.isparticipate = %d", req.IsParticipate))
  733. }
  734. 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"
  735. 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"
  736. } else if queryType == 2 {
  737. if isEnt {
  738. //是企业版
  739. personArr := []string{}
  740. personArrStrSplit := strings.Split(personArrStr, ",")
  741. for i := 0; i < len(personArrStrSplit); i++ {
  742. personArr = append(personArr, fmt.Sprintf(" FIND_IN_SET('%s', b.ent_user_ids)", personArrStrSplit[i]))
  743. }
  744. if len(personArr) > 0 {
  745. personStr := strings.Join(personArr, " or ")
  746. query = append(query, fmt.Sprintf("(%s)", personStr))
  747. }
  748. } else {
  749. //不是企业版
  750. query = append(query, fmt.Sprintf(" FIND_IN_SET('%s', b.position_ids)", personArrStr))
  751. }
  752. //// 无默认时间时
  753. if req.BidUpdateStartTime == 0 && req.BidUpdateEndTime == 0 {
  754. var start = time.Now().AddDate(0, 0, -30)
  755. query = append(query, fmt.Sprintf(" b.update_date >= '%s' ", start.Local().Format(date.Date_Full_Layout)))
  756. }
  757. // 参标状态更新时间
  758. if req.BidUpdateStartTime != 0 {
  759. bidStart_, err := time.ParseInLocation(date.Date_yyyyMMdd, fmt.Sprintf("%d", req.BidUpdateStartTime), time.Local)
  760. if err != nil {
  761. bidStart_ = time.Now().AddDate(0, 0, -30)
  762. log.Println("时间转换失败,使用默认值:", err)
  763. }
  764. bidStart := date.FormatDate(&bidStart_, date.Date_Full_Layout)
  765. query = append(query, fmt.Sprintf("b.update_date >= '%s'", bidStart))
  766. }
  767. if req.BidUpdateEndTime != 0 {
  768. bidEnd_, err := time.ParseInLocation("20060102 15:04:05", fmt.Sprintf("%d 23:59:59", req.BidUpdateEndTime), time.Local)
  769. if err != nil {
  770. bidEnd_ = time.Now().AddDate(0, 0, -30)
  771. log.Println("时间转换失败,使用默认值:", err)
  772. }
  773. bidEnd := date.FormatDate(&bidEnd_, date.Date_Full_Layout)
  774. query = append(query, fmt.Sprintf("b.update_date <= '%s'", bidEnd))
  775. }
  776. if req.BidWay != 0 {
  777. query = append(query, fmt.Sprintf("b.bid_way = %d", req.BidWay))
  778. }
  779. //参标状态:-1全部,0未参标、1已参标
  780. if req.IsParticipate == 1 {
  781. query = append(query, fmt.Sprintf("b.is_participate = %d", req.IsParticipate))
  782. }
  783. q = "select b.project_id,b.stage from participate_stage_statistics b where %s %s order by b.update_date desc"
  784. qCount = "select count(b.project_id) from participate_stage_statistics b where %s %s"
  785. } else {
  786. if isEnt {
  787. //是企业版
  788. query = append(query, fmt.Sprintf(" a.ent_user_id in (%s) ", personArrStr))
  789. joinStr = "and a.ent_id = b.ent_id"
  790. } else {
  791. query = append(query, fmt.Sprintf(" a.position_id = %s ", personArrStr))
  792. //不是企业版
  793. // 个人版
  794. joinStr = "and a.position_id = b.position_ids"
  795. }
  796. if req.StartTime != 0 && req.EndTime == 0 && req.BidUpdateStartTime == 0 && req.BidUpdateEndTime == 0 {
  797. var start = time.Now().AddDate(0, 0, -30)
  798. query = append(query, fmt.Sprintf(" a.ymd >= %s ", start.Local().Format("20060102")))
  799. }
  800. if req.StartTime != 0 {
  801. query = append(query, fmt.Sprintf(" a.ymd >= %d ", req.StartTime))
  802. }
  803. if req.EndTime != 0 {
  804. query = append(query, fmt.Sprintf(" a.ymd <= %d ", req.EndTime))
  805. }
  806. if len(req.Source) > 0 {
  807. sourceArr := []string{}
  808. for i := 0; i < len(req.Source); i++ {
  809. if req.Source[i] == 0 {
  810. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", 1))
  811. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", 2))
  812. } else {
  813. sourceArr = append(sourceArr, fmt.Sprintf(" FIND_IN_SET('%d', a.source)", req.Source[i]))
  814. }
  815. }
  816. query = append(query, fmt.Sprintf(" (%s) ", strings.Join(sourceArr, " or ")))
  817. }
  818. //参标状态:-1全部,0未参标、1已参标
  819. if req.IsParticipate != -1 {
  820. query = append(query, fmt.Sprintf("a.isparticipate = %d", req.IsParticipate))
  821. }
  822. // 投标类型 投标方式;1:直接投标 2:渠道投标',
  823. if req.BidWay != 0 {
  824. query = append(query, fmt.Sprintf("a.bid_way = %d", req.BidWay))
  825. }
  826. // 参标状态更新时间
  827. if req.BidUpdateStartTime != 0 {
  828. bidStart_, err := time.ParseInLocation(date.Date_yyyyMMdd, fmt.Sprintf("%d", req.BidUpdateStartTime), time.Local)
  829. if err != nil {
  830. bidStart_ = time.Now().AddDate(0, 0, -30)
  831. log.Println("时间转换失败,使用默认值:", err)
  832. }
  833. bidStart := date.FormatDate(&bidStart_, date.Date_Full_Layout)
  834. query = append(query, fmt.Sprintf("b.update_date >= '%s'", bidStart))
  835. }
  836. if req.BidUpdateEndTime != 0 {
  837. bidEnd_, err := time.ParseInLocation("20060102 15:04:05", fmt.Sprintf("%d 23:59:59", req.BidUpdateEndTime), time.Local)
  838. if err != nil {
  839. bidEnd_ = time.Now().AddDate(0, 0, -30)
  840. log.Println("时间转换失败,使用默认值:", err)
  841. }
  842. bidEnd := date.FormatDate(&bidEnd_, date.Date_Full_Layout)
  843. query = append(query, fmt.Sprintf("b.update_date <= '%s'", bidEnd))
  844. }
  845. 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"
  846. 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"
  847. }
  848. if len(query) > 0 {
  849. q = fmt.Sprintf(q, joinStr, strings.Join(query, " and "))
  850. qCount = fmt.Sprintf(qCount, joinStr, strings.Join(query, " and "))
  851. }
  852. q = fmt.Sprintf("%s limit %d,%d", q, (req.PageNum-1)*req.PageSize, req.PageSize)
  853. return q, qCount
  854. }
  855. type PushInfoStruct struct {
  856. Source string
  857. VisitDate string
  858. DisDate string
  859. IsDistribute int
  860. }
  861. func ProjectDetailHandle(dataList []map[string]interface{}, entId int64, positionId, positionType int) []*bxcore.ProjectDetailData {
  862. //dataList 里面包含 项目id、各阶段信息
  863. // 处理项目名称
  864. projectIdList := []string{}
  865. for i := 0; i < len(dataList); i++ {
  866. projectIdList = append(projectIdList, common.ObjToString(dataList[i]["project_id"]))
  867. }
  868. // 项目名称处理成map用于后续使用
  869. projectNameMap := map[string]string{}
  870. projectNameRs := es.GetProjectNameByProjectId(projectIdList)
  871. if projectNameRs != nil && len(*projectNameRs) > 0 {
  872. for i := 0; i < len(*projectNameRs); i++ {
  873. projectId_ := common.ObjToString((*projectNameRs)[i]["_id"])
  874. projectName_ := (*projectNameRs)[i]["projectname"]
  875. projectNameMap[projectId_] = common.ObjToString(projectName_)
  876. }
  877. }
  878. // 获取推送最新状态
  879. newPushInfo := getNewPushInfo(projectIdList, int(entId), positionId, positionType)
  880. newPushInfoMap := map[string]PushInfoStruct{}
  881. // 处理推送最新状态
  882. if newPushInfo != nil && len(*newPushInfo) > 0 {
  883. for i := 0; i < len(*newPushInfo); i++ {
  884. project_ := common.ObjToString((*newPushInfo)[i]["project_id"])
  885. info := PushInfoStruct{
  886. Source: common.ObjToString((*newPushInfo)[i]["source"]),
  887. VisitDate: common.ObjToString((*newPushInfo)[i]["visit_date"]),
  888. DisDate: common.ObjToString((*newPushInfo)[i]["dis_date"]),
  889. }
  890. newPushInfoMap[project_] = info
  891. }
  892. }
  893. results := []*bxcore.ProjectDetailData{}
  894. // 处理成最后的数据
  895. for i := 0; i < len(dataList); i++ {
  896. projectId := common.ObjToString(dataList[i]["project_id"])
  897. tmp := bxcore.ProjectDetailData{
  898. ProjectName: projectNameMap[projectId],
  899. }
  900. isDistribute_ := ""
  901. // 处理推送表相关字段
  902. if pushInfo_, ok := newPushInfoMap[projectId]; ok {
  903. sourceStr := []string{}
  904. if pushInfo_.Source != "" {
  905. isDistribute_ = "未分发"
  906. sourceSplit := strings.Split(pushInfo_.Source, ",")
  907. for j := 0; j < len(sourceSplit); j++ {
  908. if sourceSplit[j] == "3" {
  909. isDistribute_ = "已分发"
  910. }
  911. if sourceName, ok := SourceMap[sourceSplit[j]]; ok {
  912. sourceStr = append(sourceStr, sourceName)
  913. }
  914. }
  915. }
  916. tmp.Source = strings.Join(sourceStr, ",") // 处理成中文
  917. tmp.ViewDate = pushInfo_.VisitDate
  918. tmp.IsDistribute = isDistribute_
  919. tmp.DisDate = pushInfo_.DisDate
  920. } //
  921. // 处理阶段勾选信息和参标、终止参标信息
  922. if dataList[i]["stage"] != nil {
  923. s := common.ObjToString(dataList[i]["stage"])
  924. err := json.Unmarshal([]byte(strings.Replace(s, "'", "\"", -1)), &tmp.Stage)
  925. if err != nil {
  926. log.Println("stage 反序列失败", err)
  927. }
  928. }
  929. tmp.Id = encrypt.EncodeArticleId2ByCheck(projectId)
  930. results = append(results, &tmp)
  931. }
  932. return results
  933. }
  934. // 获取项目的最新推送状态信息
  935. func getNewPushInfo(projectIds []string, entId int, positionId int, positionType int) *[]map[string]interface{} {
  936. s := ""
  937. if positionType == 0 {
  938. s = fmt.Sprintf("position_id=%d", positionId)
  939. } else {
  940. s = fmt.Sprintf("ent_id=%d", entId)
  941. }
  942. sql := `
  943. SELECT
  944. 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
  945. FROM participate_push_statistics A inner join (SELECT
  946. project_id,MAX(ymd) as ymd
  947. FROM
  948. participate_push_statistics
  949. WHERE
  950. %s
  951. AND project_id IN ( "` + strings.Join(projectIds, "\",\"") + `" )
  952. GROUP BY project_id) B on (A.project_id=B.project_id and A.ymd=b.ymd) and A.%s
  953. `
  954. query := fmt.Sprintf(sql, s, s)
  955. return IC.BaseMysql.SelectBySql(query)
  956. }
  957. // GetQueryType 查询类型 0空搜索 1查左边 连右表查stage 2只查右表 3内连接
  958. // IsParticipate 接收参数时 0 全部 1 未参标 2已参标 数据库中 未参标是0
  959. func GetQueryType(in *bxcore.ProjectDetailsReq) int {
  960. //
  961. if in.BidUpdateStartTime == 0 && in.BidUpdateEndTime == 0 && in.StartTime == 0 && in.EndTime == 0 && in.IsParticipate == 0 && in.BidWay == 0 && len(in.Source) == 0 {
  962. return 0
  963. }
  964. if in.IsParticipate == 1 {
  965. // 未参标只筛选推送表 右表条件无效
  966. in.BidWay = 0
  967. in.BidUpdateStartTime = 0
  968. in.BidUpdateEndTime = 0
  969. return 1
  970. }
  971. if (in.StartTime != 0 || in.EndTime != 0 || len(in.Source) > 0) && (in.BidUpdateStartTime == 0 && in.BidUpdateEndTime == 0 && in.IsParticipate != 2) {
  972. return 1
  973. }
  974. if (in.StartTime == 0 && in.EndTime == 0 && len(in.Source) == 0) && (in.BidUpdateStartTime != 0 || in.BidUpdateEndTime == 0 || in.IsParticipate == 2 || in.BidWay != 0) {
  975. return 2
  976. }
  977. return 3
  978. }