groupblood_service.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. package service
  2. import (
  3. "database/sql"
  4. "encoding/json"
  5. "errors"
  6. "fmt"
  7. "log"
  8. "sort"
  9. "strings"
  10. "time"
  11. "gopkg.in/guregu/null.v3"
  12. "xiaoniaokuaiyan.com/xiaoniao/config"
  13. "xiaoniaokuaiyan.com/xiaoniao/entity"
  14. "xiaoniaokuaiyan.com/xiaoniao/util"
  15. )
  16. type GroupBloodService struct {
  17. *WeixinService
  18. }
  19. // 获取用户集采信息
  20. func (srv *GroupBloodService) GetGroupBloodInfo(cid int) (interface{}, error) {
  21. strSql := `select id, name, start_time,end_time from (
  22. select jicai_id from t_jicai_detail where custom_id = ? ) t1 inner join t_jicai t2 on t1.jicai_id = t2.id where t2.start_time < ? and t2.end_time > ? limit 1`
  23. db := util.GetSqlDB()
  24. var baseInfo = []struct {
  25. GroupId int `db:"id" json:"jicai_id"`
  26. Name string `db:"name" json:"jicai_name"`
  27. StartTime string `db:"start_time" json:"start_time"`
  28. EndTime string `db:"end_time" json:"end_time"`
  29. }{}
  30. var curTime = time.Now().Format("2006-01-02 15:04:05")
  31. err := db.Select(&baseInfo, strSql, cid, curTime, curTime)
  32. if err != nil {
  33. return nil, err
  34. }
  35. if len(baseInfo) == 0 {
  36. return nil, errors.New("1::group-blood info not found")
  37. }
  38. strSql = `select name, gender, age, birthday, mobile, address, detail_address from t_jicai_detail t1 left join t_order t2 on t1.order_id = t2.id where t1.jicai_id = ? and t2.custom_id = ?`
  39. var customInfo = struct {
  40. Name string `db:"name" json:"custom_name"`
  41. Gender int `db:"gender" json:"gender"`
  42. Age int `db:"age" json:"age"`
  43. Birthday string `db:"birthday" json:"birthday"`
  44. Mobile string `db:"mobile" json:"mobile"`
  45. Address string `db:"address" json:"address"`
  46. DetailAddress string `db:"detail_address" json:"detail_address"`
  47. }{}
  48. err = db.Get(&customInfo, strSql, baseInfo[0].GroupId, cid)
  49. if err != nil {
  50. return nil, err
  51. }
  52. strSql = `select t1.id, t1.subject_name, t1.subject_en, queue_len, cur_queue_no, queue_ing_no, queue_no, status
  53. from (select * from t_jicai_subject where jicai_id = ?) t1 left join (select * from t_jicai_subject_queue where custom_id = ? and status in(1,2)) t2 on t1.id = t2.subject_id order by status asc`
  54. var queueInfo = []*struct {
  55. SubjectId int `db:"id" json:"subject_id"`
  56. SubjectName string `db:"subject_name" json:"subject_name"`
  57. SubjectEn string `db:"subject_en" json:"subject_en"`
  58. QueueLen int `db:"queue_len" json:"queue_len"`
  59. CurrentQueueNo int `db:"cur_queue_no" json:"cur_queue_no"`
  60. QueueIngNo int `db:"queue_ing_no" json:"queue_ing_no"`
  61. QueueNo null.Int `db:"queue_no" json:"queue_no"`
  62. Status null.Int `db:"status" json:"status"`
  63. PreNums int `db:"-" json:"pre_nums"`
  64. }{}
  65. err = db.Select(&queueInfo, strSql, baseInfo[0].GroupId, cid)
  66. if err != nil {
  67. return nil, err
  68. }
  69. for _, item := range queueInfo {
  70. if item.Status.Valid && item.Status.Int64 == 1 {
  71. strSql = "select count(custom_id) from t_jicai_subject_queue where subject_id = ? and queue_no < ? and status =1;"
  72. var pnum int
  73. db.Get(&pnum, strSql, item.SubjectId, item.QueueNo.Int64)
  74. item.PreNums = pnum
  75. } else {
  76. item.PreNums = -1
  77. }
  78. }
  79. return map[string]interface{}{
  80. "baseInfo": baseInfo,
  81. "customInfo": customInfo,
  82. "queueInfo": queueInfo,
  83. }, nil
  84. }
  85. func (srv *GroupBloodService) Enqueue(subjectId, cid int) (interface{}, error) {
  86. db := util.GetWriteSqlDB()
  87. strSql := `select * from (select id, queue_len, cur_queue_no from t_jicai_subject where id = ? ) t1 left join
  88. (select subject_id, status, queue_no from t_jicai_subject_queue where custom_id = ? and status in (1,2) order by status asc) t2 on 1=1`
  89. var sQueueInfoList = []struct {
  90. ToSubjectId int `db:"id"`
  91. QueueLen int `db:"queue_len"`
  92. CurrentQueueNo int `db:"cur_queue_no"`
  93. Status sql.NullInt64 `db:"status"`
  94. FromSubjectId sql.NullInt64 `db:"subject_id"`
  95. QueueNo sql.NullInt64 `db:"queue_no"`
  96. }{}
  97. err := db.Select(&sQueueInfoList, strSql, subjectId, cid)
  98. if err != nil {
  99. return nil, errors.New("1::" + err.Error())
  100. }
  101. for _, sQueueInfo := range sQueueInfoList {
  102. if sQueueInfo.FromSubjectId.Valid && sQueueInfo.FromSubjectId.Int64 == int64(subjectId) {
  103. if sQueueInfo.Status.Valid && sQueueInfo.Status.Int64 == 2 {
  104. return nil, errors.New("3::already checked")
  105. }
  106. return nil, errors.New("2::already Enqueued")
  107. }
  108. }
  109. sQueueInfo := sQueueInfoList[0]
  110. tx := db.MustBegin()
  111. strSql = "insert into t_jicai_subject_queue(subject_id, custom_id, queue_no, status, created_at) values(?,?,?,?,?);"
  112. tx.MustExec(strSql, subjectId, cid, sQueueInfo.CurrentQueueNo+1, 1, time.Now().Format("2006-01-02 15:04:05"))
  113. if sQueueInfo.FromSubjectId.Valid && sQueueInfo.Status.Int64 == 1 {
  114. strSql = "update t_jicai_subject_queue set status = 3 where custom_id = ? and subject_id = ?;"
  115. sqlResult := tx.MustExec(strSql, cid, sQueueInfo.FromSubjectId.Int64)
  116. if ra, _ := sqlResult.RowsAffected(); ra <= 0 {
  117. tx.Tx.Rollback()
  118. return nil, errors.New("4::failed to update queue info")
  119. }
  120. strSql = "update t_jicai_subject set queue_len = queue_len - 1 where id = ? and queue_len > 0"
  121. tx.MustExec(strSql, sQueueInfo.FromSubjectId.Int64)
  122. }
  123. strSql = "update t_jicai_subject set queue_len = queue_len + 1, cur_queue_no = ? where id = ?"
  124. sqlResult := tx.MustExec(strSql, sQueueInfo.CurrentQueueNo+1, subjectId)
  125. if ra, _ := sqlResult.RowsAffected(); ra <= 0 {
  126. tx.Tx.Rollback()
  127. return nil, errors.New("4::failed to update queue info")
  128. }
  129. tx.Commit()
  130. go func() {
  131. client := util.GetRedis()
  132. client.Select(12)
  133. msg := map[string]interface{}{
  134. "user": "system",
  135. "subjectId": subjectId,
  136. "fromSubjectId": sQueueInfo.FromSubjectId.Int64,
  137. "oper": "ENQUEUE",
  138. "custom_id": cid,
  139. }
  140. buf, _ := json.Marshal(msg)
  141. client.Publish("groupblood-inform", string(buf))
  142. }()
  143. return true, nil
  144. }
  145. func (srv *GroupBloodService) Next(subjectId int, operType int) (interface{}, error) {
  146. var queueInfo = []struct {
  147. QueueIngNo int `db:"queue_ing_no"`
  148. QueueLen int `db:"queue_len"`
  149. CurrentQueueNo int `db:"cur_queue_no"`
  150. }{}
  151. //todo 查询当前进行中人员id
  152. strSql := "select queue_ing_no, queue_len, cur_queue_no from t_jicai_subject where id = ?"
  153. db := util.GetWriteSqlDB()
  154. err := db.Select(&queueInfo, strSql, subjectId)
  155. if err != nil {
  156. return nil, err
  157. }
  158. if len(queueInfo) == 0 {
  159. return nil, errors.New("1::can not find subject")
  160. }
  161. if queueInfo[0].QueueLen <= 0 {
  162. return nil, errors.New("2::empty queue")
  163. }
  164. var isReady = false
  165. if queueInfo[0].QueueIngNo != 0 {
  166. //将检查完的相应客户设置为完成状态
  167. var toUpStatus = 2
  168. if operType == 1 {
  169. toUpStatus = 0 //跳号
  170. }
  171. //加上status等于1的条件防止当先前队列为空再进人时queue_ing_no虽不为0但是拿这个号码的人先前状态已经被改变了,导致减员出现数据不一致的情况
  172. strSql = "update t_jicai_subject_queue set status = ? where subject_id = ? and queue_no = ? and status = 1"
  173. tx := db.MustBegin()
  174. sqlResult := tx.MustExec(strSql, toUpStatus, subjectId, queueInfo[0].QueueIngNo)
  175. if ra, _ := sqlResult.RowsAffected(); ra > 0 {
  176. //减员 加上queue_len大于0的条件防止更新之后queue_len出现负数
  177. strSql = "update t_jicai_subject set queue_len = queue_len - 1 where id = ? and queue_len > 0"
  178. sqlResult = tx.MustExec(strSql, subjectId)
  179. if ra, _ = sqlResult.RowsAffected(); ra <= 0 {
  180. tx.Tx.Rollback()
  181. } else {
  182. tx.Commit()
  183. }
  184. } else {
  185. tx.Tx.Rollback()
  186. isReady = true
  187. }
  188. }
  189. //查询被叫号人员id
  190. strSql = "select custom_id, extra, queue_no from t_jicai_subject_queue t1 left join t_custom t2 on t1.custom_id = t2.id where subject_id = ? and t1.status = 1 order by queue_no asc limit 2;"
  191. var cList = []struct {
  192. CustomId int `db:"custom_id"`
  193. QueueNo int `db:"queue_no"`
  194. Extra null.String `db:"extra"`
  195. }{}
  196. db.Select(&cList, strSql, subjectId)
  197. if len(cList) > 0 && cList[0].QueueNo > 0 {
  198. strSql = "update t_jicai_subject set queue_ing_no = ? where id = ?;"
  199. db.Exec(strSql, cList[0].QueueNo, subjectId)
  200. }
  201. go func() {
  202. client := util.GetRedis()
  203. client.Select(12)
  204. msg := map[string]interface{}{
  205. "user": "system",
  206. "subjectId": subjectId,
  207. "oper": "NEXT",
  208. }
  209. buf, _ := json.Marshal(msg)
  210. client.Publish("groupblood-inform", string(buf))
  211. //推送微信模板休息
  212. strSql = "select t2.name, t2.start_time, subject_name from t_jicai_subject t1 left join t_jicai t2 on t1.jicai_id = t2.id where t1.id = ? limit 1;"
  213. var jInfo = struct {
  214. JicaiName string `db:"name"`
  215. StartTime string `db:"start_time"`
  216. SubjectName string `db:"subject_name"`
  217. }{}
  218. err = db.Get(&jInfo, strSql, subjectId)
  219. if err != nil {
  220. log.Println(err)
  221. return
  222. }
  223. if len(cList) == 2 {
  224. if !cList[1].Extra.Valid || cList[1].Extra.String == "" {
  225. return
  226. }
  227. var uinfo = map[string]string{}
  228. err = json.Unmarshal([]byte(cList[1].Extra.String), &uinfo)
  229. if err != nil {
  230. log.Println(err)
  231. return
  232. }
  233. msg := map[string]interface{}{
  234. "touser": uinfo["openid"],
  235. "template_id": "2tQiM2Y3oCleWeF7aArhGr-Lu8bCg68ylw0aUvmTkEM",
  236. "url": config.IniConf.Section("weixin").Key("wx.front_host").Value() + "/index/activity/queue",
  237. "data": map[string]interface{}{
  238. "first": map[string]interface{}{
  239. "value": "集采准备通知",
  240. "color": "#173177",
  241. },
  242. "keyword1": map[string]interface{}{
  243. "value": jInfo.JicaiName,
  244. "color": "#173177",
  245. },
  246. "keyword2": map[string]interface{}{
  247. "value": jInfo.StartTime[0:10],
  248. "color": "#173177",
  249. },
  250. "remark": map[string]interface{}{
  251. "value": "请您做好准备尽快到" + jInfo.SubjectName + "侯检",
  252. "color": "#173177",
  253. },
  254. },
  255. }
  256. buf, _ := json.Marshal(msg)
  257. srv.WeixinService.SendTpl(string(buf), "")
  258. if isReady {
  259. uinfo = map[string]string{}
  260. err = json.Unmarshal([]byte(cList[0].Extra.String), &uinfo)
  261. if err != nil {
  262. log.Println(err)
  263. return
  264. }
  265. msg["touser"] = uinfo["openid"]
  266. buf, _ = json.Marshal(msg)
  267. srv.WeixinService.SendTpl(string(buf), "")
  268. }
  269. }
  270. }()
  271. return true, nil
  272. }
  273. func (srv *GroupBloodService) GetQueueInfo(subjectId int, status int) (interface{}, error) {
  274. var istatus string = "=1"
  275. if status == 2 {
  276. istatus = "in (2,0)"
  277. }
  278. strSql := `select t1.*, t3.name, t3.id from (select js.jicai_id, custom_id, queue_no, status from t_jicai_subject_queue jsq, t_jicai_subject js where jsq.subject_id = js.id and subject_id = ? and status ` + istatus + `) t1 left join t_jicai_detail t2 on t1.custom_id = t2.custom_id and t2.jicai_id = t1.jicai_id left join t_order t3 on t2.order_id = t3.id order by queue_no asc`
  279. db := util.GetSqlDB()
  280. var retList = []struct {
  281. QueueNo int `db:"queue_no"`
  282. Status int `db:"status"`
  283. Name string `db:"name"`
  284. OrderId string `db:"id"`
  285. }{}
  286. err := db.Select(&retList, strSql, subjectId)
  287. if err != nil {
  288. return nil, err
  289. }
  290. strSql = "select t1.queue_ing_no,t1.subject_name, t2.name, t2.start_time, t2.end_time from t_jicai_subject t1 left join t_jicai t2 on t1.jicai_id = t2.id where t1.id = ?;"
  291. var queueBaseInfo = struct {
  292. JicaiName string `db:"name" json:"jicai_name"`
  293. SubjectName string `db:"subject_name" json:"subject_name"`
  294. QueueIngNo int `db:"queue_ing_no" json:"queue_ing_no"`
  295. StartTime string `db:"start_time" json:"start_time"`
  296. EndTime string `db:"end_time" json:"end_time"`
  297. }{}
  298. err = db.Get(&queueBaseInfo, strSql, subjectId)
  299. return map[string]interface{}{
  300. "queueList": retList,
  301. "queueInfo": queueBaseInfo,
  302. }, err
  303. }
  304. func (srv *GroupBloodService) GetOrderInfo(mobile string) (interface{}, error) {
  305. strSql := "select id, name,mobile, gender,age,visit_date,blood_codes,address, detail_address, group_concat(t2.product_name) as pname,source from t_order t1 left join t_order_product t2 on t1.id = t2.order_id where mobile = ? and type ='200' and status in(2,4) and admin_remark='尚医智信集采' and (source='batch' or source='shangyizhixin') group by t1.id limit 2;"
  306. var oinfoItem = []struct {
  307. Id string `db:"id" json:"id"`
  308. CustomName string `db:"name" json:"name"`
  309. Mobile string `db:"mobile" json:"mobile"`
  310. Gender int `db:"gender" json:"gender"`
  311. Age int `db:"age" json:"age"`
  312. VisitDate string `db:"visit_date" json:"visit_date"`
  313. ProductName string `db:"pname" json:"product_name"`
  314. Source string `db:"source" json:"source"`
  315. Address null.String `db:"address" json:"address"`
  316. DetailAddress null.String `db:"detail_address" json:"detail_address"`
  317. BloodCodes null.String `db:"blood_codes" json:"blood_codes"`
  318. IsAnswered bool `db:"-" json:"is_answered"`
  319. IsGivingupAdd bool `db:"-" json:"is_givingup_add"`
  320. }{}
  321. db := util.GetSqlDB()
  322. err := db.Select(&oinfoItem, strSql, mobile)
  323. if err != nil {
  324. return nil, err
  325. }
  326. if len(oinfoItem) == 0 {
  327. return nil, errors.New("1::can not find order")
  328. }
  329. var tids []int = []int{}
  330. err = db.Select(&tids, "select id from t_activity_answer where mobile =? and is_delete='N' limit 1;", mobile)
  331. if err != nil {
  332. return nil, err
  333. }
  334. if len(tids) > 0 {
  335. oinfoItem[0].IsAnswered = true
  336. }
  337. strSql = "select id from t_jicai_keshi_log where mobile =? and detect_product_id = -3 limit 1;"
  338. tids = []int{}
  339. err = db.Select(&tids, strSql, mobile)
  340. if err != nil {
  341. return nil, err
  342. }
  343. if len(tids) > 0 {
  344. oinfoItem[0].IsGivingupAdd = true
  345. }
  346. return oinfoItem, nil
  347. }
  348. func (srv *GroupBloodService) GetCheckProgress(mobile string) (interface{}, error) {
  349. db := util.GetSqlDB()
  350. strSql := "select product_id from t_order_product where order_id in (select id from t_order where mobile = ? and status in(2,4) and type ='200' and admin_remark='尚医智信集采' and (source='batch' or source='shangyizhixin'))"
  351. var strPids = []string{}
  352. err := db.Select(&strPids, strSql, mobile)
  353. if err != nil {
  354. return nil, err
  355. }
  356. if len(strPids) == 0 {
  357. return nil, errors.New("1::can not find order")
  358. }
  359. strSql = `select t1.*, GROUP_CONCAT(t3.id, '-', t3.name) as dids, t4.tdids, t4.detect_product_name from (
  360. select id, name, is_blood, need_emptiness from t_detect_product t1 where id in (
  361. select DISTINCT detect_product_id from t_product_detect_product where product_id in (` + strings.Join(strPids, ",") +
  362. `)
  363. ) and is_blood = 'N'
  364. )t1 left JOIN t_detect_product_item t2 on t1.id = t2.detect_product_id left JOIN t_detect_item t3 on t2.detect_item_id = t3.id left join
  365. (select detect_product_id, detect_product_name, group_concat(detect_item_id, '-', status) tdids from t_jicai_keshi_log where mobile = ? group by detect_product_id) t4 on t1.id = t4.detect_product_id GROUP BY t1.id;`
  366. var progressInfo = []struct {
  367. Id int `db:"id" json:"keshi_id"`
  368. Name string `db:"name" json:"name"`
  369. IsBlood string `db:"is_blood" json:"is_blood"`
  370. Notice null.String `db:"need_emptiness" json:"notice"`
  371. Items []struct {
  372. Id string `json:"detect_item_id"`
  373. Name string `json:"name"`
  374. Status string `json:"status"`
  375. } `db:"items" json:"items"`
  376. KName null.String `db:"detect_product_name" json:"k_name"`
  377. ItemIds null.String `db:"dids" json:"-"`
  378. TargetItemIds null.String `db:"tdids" json:"-"`
  379. IsComplete string `db:"-" json:"is_complete"`
  380. }{}
  381. err = db.Select(&progressInfo, strSql, mobile)
  382. if err != nil {
  383. return nil, err
  384. }
  385. for i, l := 0, len(progressInfo); i < l; i++ {
  386. progressInfo[i].IsComplete = ""
  387. isDrop := 0
  388. var logItems = map[string]string{}
  389. if progressInfo[i].TargetItemIds.Valid {
  390. isDrop = 1
  391. logStrItems := strings.Split(progressInfo[i].TargetItemIds.String, ",")
  392. for _, strItem := range logStrItems {
  393. tps := strings.Split(strItem, "-")
  394. logItems[tps[0]] = tps[1]
  395. if tps[1] == "N" {
  396. isDrop = 2
  397. }
  398. }
  399. }
  400. if !progressInfo[i].ItemIds.Valid {
  401. return nil, errors.New("wrong base data")
  402. }
  403. titems := strings.Split(progressInfo[i].ItemIds.String, ",")
  404. if len(logItems) == len(titems) {
  405. progressInfo[i].IsComplete = "Y"
  406. if isDrop == 1 {
  407. progressInfo[i].IsComplete = "D"
  408. }
  409. }
  410. for _, titem := range titems {
  411. var status = ""
  412. pieces := strings.Split(titem, "-")
  413. if st, ok := logItems[pieces[0]]; ok {
  414. status = st
  415. }
  416. progressInfo[i].Items = append(progressInfo[i].Items, struct {
  417. Id string `json:"detect_item_id"`
  418. Name string `json:"name"`
  419. Status string `json:"status"`
  420. }{
  421. Id: pieces[0],
  422. Name: pieces[1],
  423. Status: status,
  424. })
  425. }
  426. }
  427. strSql = "select status from t_jicai_keshi_log where mobile =? and detect_product_id = -1 limit 1"
  428. var hasBlood string
  429. err = db.Get(&hasBlood, strSql, mobile)
  430. if err != nil && err != sql.ErrNoRows {
  431. return nil, err
  432. }
  433. var cpinfo = struct {
  434. Id int `db:"id" json:"keshi_id"`
  435. Name string `db:"name" json:"name"`
  436. IsBlood string `db:"is_blood" json:"is_blood"`
  437. Notice null.String `db:"need_emptiness" json:"notice"`
  438. Items []struct {
  439. Id string `json:"detect_item_id"`
  440. Name string `json:"name"`
  441. Status string `json:"status"`
  442. } `db:"items" json:"items"`
  443. KName null.String `db:"detect_product_name" json:"k_name"`
  444. ItemIds null.String `db:"dids" json:"-"`
  445. TargetItemIds null.String `db:"tdids" json:"-"`
  446. IsComplete string `db:"-" json:"is_complete"`
  447. }{
  448. Id: -1, Name: "抽血", IsBlood: "Y", Notice: null.StringFrom("需要空腹"), IsComplete: "",
  449. }
  450. if hasBlood != "" {
  451. if hasBlood == "N" {
  452. cpinfo.IsComplete = "Y"
  453. } else if hasBlood == "Y" {
  454. cpinfo.IsComplete = "D"
  455. }
  456. }
  457. progressInfo = append(progressInfo, cpinfo)
  458. strSql = "select id from t_jicai_keshi_log where mobile =? and detect_product_id = -2 limit 1;"
  459. var hasCmplete int
  460. err = db.Get(&hasCmplete, strSql, mobile)
  461. if err != nil && err != sql.ErrNoRows {
  462. return nil, err
  463. }
  464. return map[string]interface{}{
  465. "progressinfo": progressInfo,
  466. "has_complete": hasCmplete,
  467. }, nil
  468. }
  469. func (srv GroupBloodService) ConfirmChecked(param *entity.GPParam) (interface{}, error) {
  470. db := util.GetWriteSqlDB()
  471. switch param.Oper {
  472. case "COMPLETE":
  473. strSql := "insert into t_jicai_keshi_log(mobile, detect_product_id) values(?,-2);"
  474. db.Exec(strSql, param.Mobile)
  475. return true, nil
  476. case "DROP":
  477. strSql := "insert into t_jicai_keshi_log(mobile, detect_product_id, detect_item_id, status,create_time, detect_product_name) values"
  478. nowStr := time.Now().Format("2006-01-02 15:04:05")
  479. for _, gpItem := range param.DPItems {
  480. for _, ditem := range gpItem.DetectItemIds {
  481. strSql += fmt.Sprintf("('%s',%d, %d, '%s', '%s', '%s'),", param.Mobile, gpItem.DetectProductId, ditem, "Y", nowStr, gpItem.Name)
  482. }
  483. }
  484. strSql = strSql[0 : len(strSql)-1]
  485. db.Exec(strSql)
  486. return true, nil
  487. default:
  488. return nil, nil
  489. }
  490. }
  491. func splitAndSortString(values string) string {
  492. varr := strings.Split(values, ",")
  493. sort.Strings(varr)
  494. return strings.Join(varr, ",")
  495. }