|
@@ -0,0 +1,60 @@
|
|
1
|
+package cases
|
|
2
|
+
|
|
3
|
+import (
|
|
4
|
+ "jcjy/demo/models"
|
|
5
|
+ "spaceofcheng/services/models/model"
|
|
6
|
+ "strconv"
|
|
7
|
+ "strings"
|
|
8
|
+)
|
|
9
|
+
|
|
10
|
+// GetTagCount 获取标签总数
|
|
11
|
+func (m *CaseDAO) GetTagCount(caseids string) (int, error) {
|
|
12
|
+ var tags []model.SysTag
|
|
13
|
+ err := m.db.Where("status=?", models.STATUS_NORMAL).And("case_id in ('" + strings.Replace(caseids, ",", "','", -1) + "')").Find(&tags)
|
|
14
|
+ return len(tags), err
|
|
15
|
+}
|
|
16
|
+
|
|
17
|
+// TagInfo 标签
|
|
18
|
+type TagInfo struct {
|
|
19
|
+ model.TaCmsCase `xorm:"extends"`
|
|
20
|
+ CaseNames string
|
|
21
|
+}
|
|
22
|
+
|
|
23
|
+// GetTagList 根据案场获取标签
|
|
24
|
+func (m *CaseDAO) GetTagList(caseids string, page int, pageSize int) ([]TagInfo, error) {
|
|
25
|
+ var tags []TagInfo
|
|
26
|
+ sql := `select tag.*,c.case_names from sys_tag tag inner join (
|
|
27
|
+ select b.tag_id,GROUP_CONCAT(a.case_name) case_names from sys_case a inner join sys_tag_case b on a.case_id=b.case_id and a.status= ` + strconv.Itoa(models.STATUS_NORMAL) + `
|
|
28
|
+ where b.case_id in ('` + strings.Replace(caseids, ",", "','", -1) + `') and b.tag_id not in (select tag_id from sys_tag_case where case_id not in ('` +
|
|
29
|
+ strings.Replace(caseids, ",", "','", -1) + `'))
|
|
30
|
+ group by b.tag_id ) c on tag.tag_id = c.tag_id`
|
|
31
|
+
|
|
32
|
+ err := m.db.Sql(sql).Find(tags)
|
|
33
|
+ return tags, err
|
|
34
|
+}
|
|
35
|
+
|
|
36
|
+// Tag 标签
|
|
37
|
+type Tag struct {
|
|
38
|
+ model.TaCmsCase `xorm:"extends"`
|
|
39
|
+ TagCases []model.SysTagCase
|
|
40
|
+}
|
|
41
|
+
|
|
42
|
+// GetTagByID 根据ID获取标签
|
|
43
|
+func (m *CaseDAO) GetTagByID(tagid string) (*Tag, error) {
|
|
44
|
+ var tags []Tag
|
|
45
|
+ err := m.db.Table("sys_tag").Where("tag_id=?", tagid).Find(&tags)
|
|
46
|
+ if err != nil {
|
|
47
|
+ return nil, err
|
|
48
|
+ }
|
|
49
|
+ if len(tags) > 0 {
|
|
50
|
+ return &tags[0], err
|
|
51
|
+ }
|
|
52
|
+ return nil, nil
|
|
53
|
+}
|
|
54
|
+
|
|
55
|
+// GetTagCaseByTagID 根据标签ID获取标签对应案场
|
|
56
|
+func (m *CaseDAO) GetTagCaseByTagID(tagid string) ([]model.SysTagCase, error) {
|
|
57
|
+ var tagcase []model.SysTagCase
|
|
58
|
+ err := m.db.Where("tag_id=?", tagid).Find(&tagcase)
|
|
59
|
+ return tagcase, err
|
|
60
|
+}
|