purchase.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. package service
  2. import (
  3. MC "app.yhyue.com/moapp/jybase/common"
  4. "app.yhyue.com/moapp/jybase/encrypt"
  5. elastic "app.yhyue.com/moapp/jybase/es"
  6. "app.yhyue.com/moapp/jybase/redis"
  7. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  8. IC "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/init"
  9. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/model/es"
  10. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/type/bxcore"
  11. "bp.jydev.jianyu360.cn/BaseService/jyMicroservices/jyBXCore/rpc/util"
  12. "encoding/json"
  13. "fmt"
  14. "log"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. type Purchase struct {
  20. AppId string ` json:"appId,omitempty"` //剑鱼默认10000
  21. UserId string ` json:"userId,omitempty"` //用户id
  22. Phone string ` json:"phone,omitempty"` //手机号
  23. BaseUserId int64 ` json:"baseUserId,omitempty"` //base_user_id 新用户id
  24. EntId int64 ` json:"entId,omitempty"` //企业id 没有企业 企业id=0
  25. EntUserId int64 ` json:"entUserId,omitempty"` //企业用户id 当前企业下的员工id 没有企业默认0
  26. AccountId int64 ` json:"accountId,omitempty"` //账户id
  27. EntAccountId int64 ` json:"entAccountId,omitempty"` //企业账户id
  28. PositionType int64 ` json:"positionType,omitempty"` //职位类型 0个人 1企业
  29. PositionId int64 ` json:"positionId,omitempty"` //职位id
  30. MgoUserId string ` json:"mgoUserId,omitempty"` //原userId
  31. PageNum int64 ` json:"pageNum,omitempty"` //当前页码
  32. PageSize int64 ` json:"pageSize,omitempty"` //每页数量
  33. PublishTime string ` json:"publishTime,omitempty"` //发布时间
  34. SelectType string ` json:"selectType,omitempty"` //搜索范围:
  35. DomainFirstType string ` json:"domainFirstType,omitempty"` //领域 一级
  36. DomainSecondType string ` json:"domainSecondType,omitempty"` //领域 二级
  37. DomainThirdType string ` json:"domainThirdType,omitempty"` //领域 三级
  38. DeadlineStatus int64 ` json:"deadlineStatus,omitempty"` //报名截止状态
  39. DeadlineTime string ` json:"deadlineTime,omitempty"` //报名截止时间
  40. DeadlineStart int64 ` json:"deadlineStart,omitempty"` //报名截止时间-开始
  41. DeadlineEnd int64 ` json:"deadlineEnd,omitempty"` //报名截止时间-结束
  42. DeliveryArea string ` json:"deliveryArea,omitempty"` //交付地点-省份
  43. DeliveryCity string ` json:"deliveryCity,omitempty"` //交付地点-城市
  44. DeliveryDistrict string ` json:"deliveryDistrict,omitempty"` //交付地点-县区
  45. ProjectArea string ` json:"projectArea,omitempty"` //项目地区-省份
  46. ProjectCity string ` json:"projectCity,omitempty"` //项目地区-城市
  47. ProjectDistrict string ` json:"projectDistrict,omitempty"` //项目地区-县区
  48. Industry string ` json:"industry,omitempty"` //行业
  49. FileExists int64 ` json:"fileExists,omitempty"` //是否有附件
  50. Publisher int64 ` json:"publisher,omitempty"` //发布者:可选:全部、用户发布:1、平台发布:2。
  51. KeyWords string ` json:"keyWords,omitempty"` //关键词:多个空格隔开(主)
  52. AdditionalWords string ` json:"additionalWords,omitempty"` //关键词:附加关键词(副:五组,每组最多15个字符)
  53. SearchMode int64 ` json:"searchMode,omitempty"` //搜索模式:0:精准搜索;1:模糊搜索
  54. WordsMode int64 ` json:"wordsMode,omitempty"` //搜索关键词模式;默认0:包含所有,1:包含任意
  55. UserAgent string ` json:"userAgent,omitempty"` //请求头信息
  56. Platform string ` json:"platform,omitempty"` //请求平台
  57. TipMsg string `json:"tipMsg"` //关键词提示信息
  58. HighlightWords string `json:"highlightWords"` //需要高亮的词,多个,号分割
  59. Total int64 `json:"total"` //数据总量
  60. }
  61. func NewPurchase(in *bxcore.PurchaseReq) *Purchase {
  62. baseUserId, _ := strconv.ParseInt(in.NewUserId, 10, 64)
  63. accountId, _ := strconv.ParseInt(in.AccountId, 10, 64)
  64. positionType, _ := strconv.ParseInt(in.PositionType, 10, 64)
  65. positionId, _ := strconv.ParseInt(in.PositionId, 10, 64)
  66. return &Purchase{
  67. AppId: in.AppId,
  68. UserId: in.UserId,
  69. Phone: in.Phone,
  70. BaseUserId: baseUserId,
  71. EntId: in.EntId,
  72. EntUserId: in.EntUserId,
  73. AccountId: accountId,
  74. EntAccountId: in.EntAccountId,
  75. PositionType: positionType,
  76. PositionId: positionId,
  77. MgoUserId: in.MgoUserId,
  78. PageNum: in.PageNum,
  79. PageSize: in.PageSize,
  80. PublishTime: in.PublishTime,
  81. SelectType: in.SelectType,
  82. DomainFirstType: in.DomainFirstType,
  83. DomainSecondType: in.DomainSecondType,
  84. DomainThirdType: in.DomainThirdType,
  85. DeadlineStatus: in.DeadlineStatus,
  86. DeadlineTime: in.DeadlineTime,
  87. DeliveryArea: in.DeliveryArea,
  88. DeliveryCity: in.DeliveryCity,
  89. DeliveryDistrict: in.DeliveryDistrict,
  90. ProjectArea: in.ProjectArea,
  91. ProjectCity: in.ProjectCity,
  92. ProjectDistrict: in.ProjectDistrict,
  93. Industry: in.Industry,
  94. FileExists: in.FileExists,
  95. Publisher: in.Publisher,
  96. KeyWords: in.KeyWords,
  97. AdditionalWords: in.AdditionalWords,
  98. SearchMode: in.SearchMode,
  99. WordsMode: in.WordsMode,
  100. UserAgent: in.UserAgent,
  101. Platform: in.Platform,
  102. }
  103. }
  104. // 格式化
  105. func (p *Purchase) PurchaseListFormat(res *[]map[string]interface{}) (list []*bxcore.PurchaseList) {
  106. for _, rv := range *res {
  107. id := MC.InterfaceToStr(rv["id"])
  108. list = append(list, &bxcore.PurchaseList{
  109. Id: encrypt.EncodeArticleId2ByCheck(id),
  110. Area: "",
  111. City: "",
  112. District: "",
  113. RegionUrl: "",
  114. BuyerClass: "",
  115. PublishTime: 0,
  116. FileExists: false,
  117. Title: "",
  118. Price: 0,
  119. Buyer: "",
  120. BuyerTel: "",
  121. DeadlineTime: "",
  122. DeliveryLoc: "",
  123. Industry: "",
  124. })
  125. }
  126. return
  127. }
  128. func (p *Purchase) PurchaseQuery() (query string) {
  129. var (
  130. wordsMusts, wordsShould, must, mustNot []string
  131. selectTypeArr = strings.Split(p.SelectType, ",")
  132. selectType = fmt.Sprintf(`"%s"`, strings.Join(selectTypeArr, "\",\""))
  133. )
  134. //发布时间
  135. if len(strings.Split(p.PublishTime, "-")) > 1 {
  136. var (
  137. timeQuery string
  138. startTime, endTime = strings.Split(p.PublishTime, "-")[0], strings.Split(p.PublishTime, "-")[1]
  139. )
  140. if startTime != "" || endTime != "" {
  141. timeQuery += `{"range":{"publishtime":{`
  142. if startTime != "" {
  143. timeQuery += `"gte":` + startTime
  144. }
  145. if startTime != "" && endTime != "" {
  146. timeQuery += `,`
  147. }
  148. if endTime != "" {
  149. timeQuery += `"lt":` + endTime
  150. }
  151. timeQuery += `}}}`
  152. }
  153. if timeQuery != "" {
  154. must = append(must, timeQuery)
  155. }
  156. }
  157. // 关键词
  158. if p.KeyWords != "" {
  159. var (
  160. keyWordsMusts []string
  161. )
  162. for _, v := range strings.Split(p.KeyWords, IC.C.JYKeyMark) {
  163. if elastic.ReplaceYH(v) == "" {
  164. continue
  165. }
  166. keyWordsMusts = append(keyWordsMusts, fmt.Sprintf(fmt.Sprintf(es.MultiMatch, "%s", selectType), elastic.ReplaceYH(v)))
  167. }
  168. //搜索关键词模式;默认0:包含所有,1:包含任意
  169. if p.WordsMode == 1 {
  170. wordsShould = append(wordsShould, fmt.Sprintf(elastic.NgramMust, strings.Join(keyWordsMusts, ",")))
  171. } else {
  172. wordsMusts = append(wordsMusts, keyWordsMusts...)
  173. }
  174. }
  175. //附加词
  176. if p.AdditionalWords != "" {
  177. for _, aws := range strings.Split(p.AdditionalWords, ",") {
  178. //多组附加词,每组间,号隔开。每组内如果关键词中间有空格,自动分词
  179. var (
  180. addWordsMusts []string
  181. )
  182. for _, v := range strings.Split(aws, IC.C.JYKeyMark) {
  183. if elastic.ReplaceYH(v) == "" {
  184. continue
  185. }
  186. addWordsStr := fmt.Sprintf(fmt.Sprintf(es.MultiMatch, "%s", selectType), elastic.ReplaceYH(v))
  187. if p.WordsMode == 0 {
  188. wordsMusts = append(wordsMusts, addWordsStr)
  189. } else {
  190. addWordsMusts = append(addWordsMusts, addWordsStr)
  191. }
  192. }
  193. //搜索关键词模式;默认0:包含所有,1:包含任意
  194. if len(addWordsMusts) > 0 {
  195. wordsShould = append(wordsShould, fmt.Sprintf(elastic.NgramMust, strings.Join(addWordsMusts, ",")))
  196. }
  197. }
  198. }
  199. //搜索关键词模式;默认0:包含所有,1:包含任意
  200. //包含任意一组
  201. if len(wordsShould) > 0 {
  202. must = append(must, fmt.Sprintf(es.QueryBoolShould, strings.Join(wordsShould, ",")))
  203. } else if len(wordsMusts) > 0 {
  204. must = append(must, fmt.Sprintf(elastic.NgramMust, strings.Join(wordsMusts, ",")))
  205. }
  206. //行业
  207. if p.Industry != "" {
  208. must = append(must, fmt.Sprintf(es.QueryBoolMustA, "s_subscopeclass", `"`+strings.ReplaceAll(p.Industry, ",", `","`)+`"`))
  209. }
  210. //附件
  211. if p.FileExists != 0 {
  212. switch p.FileExists {
  213. case 1: //有附件
  214. must = append(must, fmt.Sprintf(es.QueryBoolMustTermBool, "isValidFile", true))
  215. case -1: //无附件
  216. mustNot = append(mustNot, fmt.Sprintf(es.QueryBoolMustTermBool, "isValidFile", true))
  217. }
  218. }
  219. //项目地区
  220. var (
  221. areaQuery []string
  222. areaTerms = `{"terms":{"%s":["%s"]}}`
  223. )
  224. if p.ProjectArea != "" {
  225. areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "area", strings.ReplaceAll(p.ProjectArea, ",", "\",\"")))
  226. }
  227. if p.ProjectCity != "" {
  228. areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "city", strings.ReplaceAll(p.ProjectArea, ",", "\",\"")))
  229. }
  230. if p.ProjectDistrict != "" {
  231. for _, v := range strings.Split(p.ProjectDistrict, ",") {
  232. if len(strings.Split(v, "_")) > 1 {
  233. cityName := strings.Split(v, "_")[0]
  234. districtName := strings.Split(v, "_")[1]
  235. queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"city":["%s"]}},{"terms":{"district":["%s"]}}]}}`
  236. areaQuery = append(areaQuery, fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName))
  237. }
  238. }
  239. }
  240. if len(areaQuery) > 0 {
  241. must = append(must, fmt.Sprintf(es.QueryBoolShould, strings.Join(areaQuery, ",")))
  242. }
  243. //交付地点
  244. areaQuery = []string{}
  245. if p.DeliveryArea != "" {
  246. areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "deliver_area", strings.ReplaceAll(p.DeliveryArea, ",", "\",\"")))
  247. }
  248. if p.DeliveryCity != "" {
  249. areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "deliver_city", strings.ReplaceAll(p.DeliveryCity, ",", "\",\"")))
  250. }
  251. if p.DeliveryDistrict != "" {
  252. for _, v := range strings.Split(p.DeliveryDistrict, ",") {
  253. if len(strings.Split(v, "_")) > 1 {
  254. cityName := strings.Split(v, "_")[0]
  255. districtName := strings.Split(v, "_")[1]
  256. queryBoolMustAndDistrict := `{"bool":{"must":[{"terms":{"deliver_city":["%s"]}},{"terms":{"deliver_district":["%s"]}}]}}`
  257. areaQuery = append(areaQuery, fmt.Sprintf(queryBoolMustAndDistrict, cityName, districtName))
  258. }
  259. }
  260. }
  261. if len(areaQuery) > 0 {
  262. must = append(must, fmt.Sprintf(es.QueryBoolShould, strings.Join(areaQuery, ",")))
  263. }
  264. //发布方式
  265. if p.Publisher > 0 {
  266. must = append(must, fmt.Sprintf(es.QueryBoolMustTerm, "public_type", fmt.Sprintf("%d", p.Publisher)))
  267. }
  268. //截止时间
  269. if p.DeadlineStart > 0 || p.DeadlineEnd > 0 {
  270. var timeQuery string
  271. timeQuery += `{"range":{"signendtime":{`
  272. if p.DeadlineStart > 0 {
  273. timeQuery += fmt.Sprintf(`"gte":%d`, p.DeadlineStart)
  274. }
  275. if p.DeadlineStart > 0 && p.DeadlineEnd > 0 {
  276. timeQuery += `,`
  277. }
  278. if p.DeadlineEnd > 0 {
  279. timeQuery += fmt.Sprintf(`"lt":%d`, p.DeadlineEnd)
  280. }
  281. timeQuery += `}}}`
  282. }
  283. //领域
  284. areaQuery = []string{}
  285. if p.DomainSecondType != "" {
  286. areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "domain_secondtype", strings.ReplaceAll(p.DomainSecondType, ",", "\",\"")))
  287. }
  288. if p.DomainThirdType != "" {
  289. areaQuery = append(areaQuery, fmt.Sprintf(areaTerms, "domain_thirdtype", strings.ReplaceAll(p.DomainThirdType, ",", "\",\"")))
  290. }
  291. if len(areaQuery) > 0 {
  292. must = append(must, fmt.Sprintf(es.QueryBoolShould, strings.Join(areaQuery, ",")))
  293. }
  294. //直采 采购信息 搜索
  295. query = fmt.Sprintf(query, strings.Join(must, ","), strings.Join(mustNot, ","))
  296. log.Println("zc-query:", query)
  297. return
  298. }
  299. func (p *Purchase) FindDataFromES() (total int64, list *[]map[string]interface{}, err error) {
  300. var (
  301. start = int((p.PageNum - 1) * p.PageSize)
  302. )
  303. biddingSearch := es.SearchByES{
  304. Index: es.PurchaseIndex,
  305. IType: es.PurchaseType,
  306. Query: p.PurchaseQuery(),
  307. FindFields: p.SelectType,
  308. Order: es.PurchaseSearchSort,
  309. Fields: es.PurchaseBaseField,
  310. Start: start,
  311. Limit: int(p.PageSize),
  312. Count: 0, //高亮正文数量
  313. HighLight: false, //是否高亮正文
  314. }
  315. total, list = biddingSearch.GetAllByNgramWithCount(es.LoginTypePay)
  316. fmt.Println(total, "-------------------", *list)
  317. p.Total = total
  318. total = int64(util.SearchPageSize * util.SearchMaxPageNum)
  319. if p.Total > total {
  320. p.Total = total
  321. }
  322. return
  323. }
  324. var (
  325. redisCode = "newother"
  326. purchaseCacheKey = "purchase_cache_data"
  327. purchaseCacheExpire = 4 * 60 * 60
  328. )
  329. func (p *Purchase) GetPurchaseData() (list []*bxcore.PurchaseList, err error) {
  330. var (
  331. res *[]map[string]interface{}
  332. )
  333. if p.IsEmptySearch() {
  334. //查缓存
  335. cacheBytes, err := redis.GetBytes(redisCode, purchaseCacheKey)
  336. start := int((p.PageNum - 1) * p.PageSize)
  337. pageSize := p.PageSize
  338. if err == nil && len(*cacheBytes) > start {
  339. end := int(p.PageNum * p.PageSize)
  340. if end > len(*cacheBytes) {
  341. end = len(*cacheBytes)
  342. }
  343. err = json.Unmarshal((*cacheBytes)[start:end], res)
  344. }
  345. if len(*res) == 0 {
  346. p.PageNum = 1
  347. p.PageSize = int64(util.SearchPageSize * util.SearchMaxPageNum)
  348. _, res, err = p.FindDataFromES()
  349. *cacheBytes, err = json.Marshal(res)
  350. if err == nil && len(*cacheBytes) > 0 {
  351. err = redis.PutBytes(redisCode, purchaseCacheKey, cacheBytes, purchaseCacheExpire)
  352. }
  353. }
  354. *res = (*res)[start:pageSize]
  355. } else {
  356. //实时查询
  357. //未登录查询 限制并发数
  358. _, res, err = p.FindDataFromES()
  359. }
  360. if len(*res) > 0 {
  361. p.PurchaseListFormat(res)
  362. }
  363. return
  364. }
  365. // 关键词 附加词 行业
  366. func (p *Purchase) IsEmptySearch() bool {
  367. if p.KeyWords != "" || p.AdditionalWords != "" || p.Industry != "" {
  368. return false
  369. }
  370. return true
  371. }
  372. var (
  373. purchaseSelectTypeMap = map[string]bool{
  374. "title": true,
  375. "purchasing": true,
  376. }
  377. tipMsg = "“%s“及其后面的字词均被忽略,因为剑鱼标讯的查询限制在%d个汉字以内。"
  378. )
  379. // 筛选条件格式化
  380. func (p *Purchase) FilterCriteriaFormat() {
  381. //搜索范围
  382. if p.SelectType != "" {
  383. var selectTypes []string
  384. for _, sv := range strings.Split(p.SelectType, ",") {
  385. if purchaseSelectTypeMap[sv] {
  386. selectTypes = append(selectTypes, sv)
  387. }
  388. }
  389. if len(selectTypes) > 0 {
  390. p.SelectType = strings.Join(selectTypes, ",")
  391. }
  392. }
  393. if p.SelectType == "" {
  394. p.SelectType = "title"
  395. }
  396. // p.SearchMode 搜索模式:0:精准搜索;1:模糊搜索
  397. // 精准搜索:不分词,完全匹配;(中间带空格的关键词组自动分词)
  398. // 模糊搜索:对用户输入的单个关键词进行分词处理,但必须都存在;
  399. if p.SearchMode < 0 || p.SearchMode > 1 {
  400. p.SearchMode = 0
  401. }
  402. // p.WordsMode 搜索关键词模式;默认0:包含所有,1:包含任意
  403. if p.WordsMode < 0 || p.WordsMode > 1 {
  404. p.WordsMode = 0
  405. }
  406. //发布时间--默认最近一年
  407. if p.PublishTime == "" {
  408. p.PublishTime = fmt.Sprintf("%d-%d", time.Now().AddDate(-1, 0, 0).Unix(), time.Now().Unix())
  409. }
  410. //默认每页数据量
  411. if p.PageSize <= 0 || p.PageSize > 100 {
  412. p.PageSize = 50
  413. }
  414. //第一页
  415. if p.PageNum <= 0 || p.PageNum > int64(IC.C.DefaultBidInfo.Count)/p.PageSize {
  416. p.PageNum = 1
  417. }
  418. //行业
  419. if p.Industry != "" {
  420. p.Industry = strings.TrimSpace(p.Industry)
  421. //P510 行业:其它
  422. if qt := jy.IndustryHandle(p.Industry); len(qt) > 0 {
  423. p.Industry = fmt.Sprintf("%s,%s", p.Industry, strings.Join(qt, ","))
  424. }
  425. }
  426. var (
  427. searchWords []string
  428. )
  429. //关键词
  430. if p.KeyWords != "" {
  431. p.KeyWords = strings.TrimSpace(p.KeyWords)
  432. _, p.TipMsg, p.KeyWords = util.InterceptSearchKW(p.KeyWords, MC.IntAllDef(IC.C.KeywordsLimit, 35), true)
  433. if p.TipMsg != "" {
  434. p.TipMsg = fmt.Sprintf(tipMsg, p.TipMsg, MC.IntAllDef(IC.C.KeywordsLimit, 35))
  435. }
  436. // in.SearchMode 搜索模式:0:精准搜索;1:模糊搜索
  437. // 精准搜索:不分词,完全匹配;(中间带空格的关键词组自动分词)
  438. // 模糊搜索:对用户输入的单个关键词进行分词处理,但必须都存在;
  439. //主关键词词组
  440. if p.SearchMode == 1 {
  441. if ikWords := util.HttpEs(p.KeyWords, "ik_smart", IC.DB.Es.Addr); ikWords != "" {
  442. p.KeyWords = jy.KeywordsProcessing(ikWords, IC.C.JYKeyMark)
  443. }
  444. }
  445. searchWords = append(searchWords, p.KeyWords)
  446. }
  447. //附加词 每组附加词不能超过15个字符
  448. if p.AdditionalWords != "" {
  449. var additionalWords []string
  450. for _, ak := range strings.Split(p.AdditionalWords, ",") {
  451. if len([]rune(ak)) > 15 {
  452. additionalWords = append(additionalWords, string([]rune(ak)[:15]))
  453. } else {
  454. additionalWords = append(additionalWords, ak)
  455. }
  456. }
  457. p.AdditionalWords = strings.Join(additionalWords, ",") //分组不变
  458. //多组附加词,每组间,号隔开。每组内如果关键词中间有空格,自动分词
  459. if p.SearchMode == 1 {
  460. var (
  461. addWords []string
  462. )
  463. for _, awv := range strings.Split(p.AdditionalWords, ",") {
  464. if strings.TrimSpace(awv) != "" {
  465. if ikWords := util.HttpEs(awv, "ik_smart", IC.DB.Es.Addr); ikWords != "" {
  466. addWords = append(addWords, jy.KeywordsProcessing(ikWords, IC.C.JYKeyMark))
  467. }
  468. }
  469. }
  470. if len(addWords) > 0 {
  471. p.AdditionalWords = strings.Join(addWords, ",")
  472. }
  473. }
  474. searchWords = append(searchWords, strings.Split(p.AdditionalWords, ",")...)
  475. }
  476. p.HighlightWords = strings.Join(searchWords, ",")
  477. //报名截止
  478. if p.DeadlineStatus < 0 || p.DeadlineStatus > 2 {
  479. p.DeadlineStatus = 0
  480. }
  481. if len(strings.Split(p.DeadlineTime, "-")) > 1 {
  482. p.DeadlineStart, _ = strconv.ParseInt(strings.Split(p.DeadlineTime, "-")[0], 10, 64)
  483. p.DeadlineEnd, _ = strconv.ParseInt(strings.Split(p.DeadlineTime, "-")[1], 10, 64)
  484. if p.DeadlineEnd > p.DeadlineStart {
  485. var deadline = p.DeadlineStart
  486. p.DeadlineStart = p.DeadlineEnd
  487. p.DeadlineEnd = deadline
  488. }
  489. }
  490. switch p.DeadlineStatus {
  491. case 1: //未截止
  492. if p.DeadlineEnd < time.Now().Unix() {
  493. p.DeadlineStart = time.Now().Unix()
  494. p.DeadlineEnd = 0
  495. }
  496. case 2: //已截止
  497. if p.DeadlineEnd > time.Now().Unix() {
  498. p.DeadlineStart = 0
  499. p.DeadlineEnd = time.Now().Unix()
  500. }
  501. }
  502. //空搜索 其它筛选条件 无效
  503. if p.IsEmptySearch() {
  504. //
  505. p.DomainFirstType = ""
  506. p.DomainSecondType = ""
  507. p.DomainThirdType = ""
  508. p.DeadlineStatus = 0
  509. p.DeadlineStart = 0
  510. p.DeadlineEnd = 0
  511. p.DeliveryArea = ""
  512. p.DeliveryCity = ""
  513. p.DeliveryDistrict = ""
  514. p.ProjectArea = ""
  515. p.ProjectCity = ""
  516. p.ProjectDistrict = ""
  517. p.FileExists = 0
  518. p.Publisher = 0
  519. }
  520. }