participateStatistics.go 40 KB

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