fix
wangpengfei
2023-08-17 f92bd29f9fff372d899d8e706b126c361dad292a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package service
 
import (
    "aps_crm/model"
    "aps_crm/model/request"
    "aps_crm/pkg/ecode"
)
 
type StatusService struct{}
 
func (StatusService) AddStatus(status *model.Status) int {
    err := model.NewStatusSearch().Create(status)
    if err != nil {
        return ecode.StatusExist
    }
 
    return ecode.OK
}
 
func (StatusService) DeleteStatus(id int) int {
    _, err := model.NewStatusSearch().SetId(id).Find()
    if err != nil {
        return ecode.StatusNotExist
    }
 
    err = model.NewStatusSearch().SetId(id).Delete()
    if err != nil {
        return ecode.StatusNotExist
    }
    return ecode.OK
}
 
func (StatusService) GetStatusList() ([]*model.Status, int) {
    list, err := model.NewStatusSearch().FindAll()
    if err != nil {
        return nil, ecode.StatusListErr
    }
 
    return list, ecode.OK
}
 
func (StatusService) UpdateStatus(statuses []*request.UpdateStatus) int {
    for _, v := range statuses {
        // check status exist
        _, err := model.NewStatusSearch().SetId(v.Id).Find()
        if err != nil {
            return ecode.StatusNotExist
        }
 
        err = model.NewStatusSearch().SetId(v.Id).Updates(map[string]interface{}{
            "name": v.Name,
        })
        if err != nil {
            return ecode.StatusSetErr
        }
    }
 
    return ecode.OK
}