|
|
1
|
+package chance
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "fmt"
|
|
|
5
|
+ "github.com/astaxie/beego"
|
|
|
6
|
+ "github.com/astaxie/beego/httplib"
|
|
|
7
|
+ "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
|
|
|
8
|
+ "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
|
|
|
9
|
+ "io/ioutil"
|
|
|
10
|
+ "net/http"
|
|
|
11
|
+ "opp/models"
|
|
|
12
|
+ "opp/protocol"
|
|
|
13
|
+
|
|
|
14
|
+ "encoding/json"
|
|
|
15
|
+)
|
|
|
16
|
+
|
|
|
17
|
+type SuplusApprove struct {
|
|
|
18
|
+}
|
|
|
19
|
+
|
|
|
20
|
+var (
|
|
|
21
|
+ ErrorRequestSuplus = fmt.Errorf("请求素加后台失败")
|
|
|
22
|
+)
|
|
|
23
|
+
|
|
|
24
|
+var ApproveSign = "CHANCE"
|
|
|
25
|
+
|
|
|
26
|
+const (
|
|
|
27
|
+ NewApproveInstance = "/approve-instances/new-approve-instance"
|
|
|
28
|
+ ApproveItem = "/approve-processes/approve-item"
|
|
|
29
|
+ ApproveIntegrate = "/approve-processes/integrate"
|
|
|
30
|
+)
|
|
|
31
|
+
|
|
|
32
|
+//新增审批实例
|
|
|
33
|
+func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, process []*models.AuditFlowProcess) (err error) {
|
|
|
34
|
+ var (
|
|
|
35
|
+ request NewApproveInstanceRequest
|
|
|
36
|
+ response NewApproveInstanceResponse
|
|
|
37
|
+ mapApproves map[int]Approve = make(map[int]Approve)
|
|
|
38
|
+ relativeId int64
|
|
|
39
|
+ userCompany *models.UserCompany
|
|
|
40
|
+ )
|
|
|
41
|
+ if userCompany, err = models.GetUserCompanyByUserId(header.UserId, header.CompanyId); err != nil {
|
|
|
42
|
+ log.Error(err)
|
|
|
43
|
+ return
|
|
|
44
|
+ }
|
|
|
45
|
+ request = NewApproveInstanceRequest{
|
|
|
46
|
+ CompanyId: header.CompanyId,
|
|
|
47
|
+ Approver: userCompany.NickName,
|
|
|
48
|
+ Uid: userCompany.Id,
|
|
|
49
|
+ Sign: ApproveSign,
|
|
|
50
|
+ Type: 1,
|
|
|
51
|
+ }
|
|
|
52
|
+ for i := range process {
|
|
|
53
|
+ var (
|
|
|
54
|
+ approve Approve
|
|
|
55
|
+ approveType int //审批类型
|
|
|
56
|
+ approveWay int //审批方式
|
|
|
57
|
+ approver *models.User
|
|
|
58
|
+ )
|
|
|
59
|
+ item := process[i]
|
|
|
60
|
+ if relativeId == 0 {
|
|
|
61
|
+ relativeId = item.ChanceId
|
|
|
62
|
+ }
|
|
|
63
|
+ if _, ok := mapApproves[i]; ok {
|
|
|
64
|
+ approve = mapApproves[i]
|
|
|
65
|
+ } else {
|
|
|
66
|
+ approveType = item.AuditFlowType
|
|
|
67
|
+ if approveType == protocol.AuditBySpecailUser {
|
|
|
68
|
+ approveType = protocol.AuditByUser
|
|
|
69
|
+ }
|
|
|
70
|
+ if item.ActionType == protocol.ActionTypeAnd {
|
|
|
71
|
+ approveWay = 1 // 会签
|
|
|
72
|
+ } else {
|
|
|
73
|
+ approveWay = 2 //或签
|
|
|
74
|
+ }
|
|
|
75
|
+ mapApproves[i] = Approve{
|
|
|
76
|
+ ApproveType: item.AuditFlowType,
|
|
|
77
|
+ ApproveWay: approveWay,
|
|
|
78
|
+ }
|
|
|
79
|
+ }
|
|
|
80
|
+ if approver, err = models.GetUserByUcid(item.Uid); err != nil {
|
|
|
81
|
+ log.Error(err)
|
|
|
82
|
+ return
|
|
|
83
|
+ }
|
|
|
84
|
+ approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{
|
|
|
85
|
+ Uid: item.Uid,
|
|
|
86
|
+ Name: approver.NickName,
|
|
|
87
|
+ })
|
|
|
88
|
+ }
|
|
|
89
|
+ request.RelativeId = relativeId
|
|
|
90
|
+ for i := 0; i < len(mapApproves); i++ {
|
|
|
91
|
+ if v, ok := mapApproves[i]; ok {
|
|
|
92
|
+ request.Approves = append(request.Approves, v)
|
|
|
93
|
+ }
|
|
|
94
|
+ }
|
|
|
95
|
+ if s.DoRequest(NewApproveInstance, http.MethodPost, request, &response); err != nil {
|
|
|
96
|
+ log.Error(err)
|
|
|
97
|
+ }
|
|
|
98
|
+ log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", NewApproveInstance, common.AssertJson(request), common.AssertJson(response)))
|
|
|
99
|
+ return
|
|
|
100
|
+}
|
|
|
101
|
+
|
|
|
102
|
+//审批操作
|
|
|
103
|
+func (s SuplusApprove) ApproveItem(header *protocol.RequestHeader, approveType int, chanceId int64) (response ApproveItemResponse, err error) {
|
|
|
104
|
+ var (
|
|
|
105
|
+ request ApproveItemRequest = ApproveItemRequest{
|
|
|
106
|
+ RelativeId: chanceId,
|
|
|
107
|
+ Type: approveType,
|
|
|
108
|
+ Suggestion: "",
|
|
|
109
|
+ Sign: ApproveSign,
|
|
|
110
|
+ ApproveType: 2,
|
|
|
111
|
+ Uid: header.UserId,
|
|
|
112
|
+ }
|
|
|
113
|
+ )
|
|
|
114
|
+ if s.DoRequest(ApproveItem, http.MethodPost, request, &response); err != nil {
|
|
|
115
|
+ log.Error(err)
|
|
|
116
|
+ }
|
|
|
117
|
+ log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", ApproveItem, common.AssertJson(request), common.AssertJson(response)))
|
|
|
118
|
+ return
|
|
|
119
|
+}
|
|
|
120
|
+
|
|
|
121
|
+//审批列表
|
|
|
122
|
+func (s SuplusApprove) ApproveIntegrate(header *protocol.RequestHeader, chanceId int64) (response ApproveIntegrateResponse, err error) {
|
|
|
123
|
+ var ()
|
|
|
124
|
+ url := fmt.Sprintf("%v?sign=%v&relativeId=%v", ApproveIntegrate, ApproveSign, chanceId)
|
|
|
125
|
+ if s.DoRequest(url, http.MethodGet, nil, &response); err != nil {
|
|
|
126
|
+ log.Error(err)
|
|
|
127
|
+ }
|
|
|
128
|
+ log.Info(fmt.Sprintf("success request suplus-approve:%v response:%v", url, common.AssertJson(response)))
|
|
|
129
|
+ return
|
|
|
130
|
+}
|
|
|
131
|
+
|
|
|
132
|
+//请求
|
|
|
133
|
+func (s SuplusApprove) DoRequest(method string, methodType string, request interface{}, response interface{}) (err error) {
|
|
|
134
|
+ var (
|
|
|
135
|
+ httpRsp *http.Response
|
|
|
136
|
+ httpReq *httplib.BeegoHTTPRequest
|
|
|
137
|
+ url = beego.AppConfig.String("suplus_host") + method
|
|
|
138
|
+ data []byte
|
|
|
139
|
+ message protocol.Message
|
|
|
140
|
+ )
|
|
|
141
|
+ if methodType == http.MethodPost {
|
|
|
142
|
+ httpReq = httplib.Post(url)
|
|
|
143
|
+ } else if methodType == http.MethodGet {
|
|
|
144
|
+ httpReq = httplib.Get(url)
|
|
|
145
|
+ }
|
|
|
146
|
+ if request != nil {
|
|
|
147
|
+ httpReq.JSONBody(request)
|
|
|
148
|
+ }
|
|
|
149
|
+ if httpRsp, err = httpReq.DoRequest(); err != nil {
|
|
|
150
|
+ log.Error(err)
|
|
|
151
|
+ return
|
|
|
152
|
+ }
|
|
|
153
|
+ data, err = ioutil.ReadAll(httpRsp.Body)
|
|
|
154
|
+ defer httpRsp.Body.Close()
|
|
|
155
|
+ if err != nil {
|
|
|
156
|
+ log.Error(err)
|
|
|
157
|
+ return
|
|
|
158
|
+ }
|
|
|
159
|
+ if err = json.Unmarshal(data, &message); err != nil {
|
|
|
160
|
+ log.Debug(url, "response:", string(data))
|
|
|
161
|
+ log.Error(err)
|
|
|
162
|
+ return
|
|
|
163
|
+ }
|
|
|
164
|
+ if message.Errno != 0 {
|
|
|
165
|
+ err = fmt.Errorf("request-%v response-code:%v msg:%v", url, message.Errno, message.Errmsg)
|
|
|
166
|
+ }
|
|
|
167
|
+ var responseData string
|
|
|
168
|
+ if len(data) > 500 {
|
|
|
169
|
+ responseData = string(data[:200])
|
|
|
170
|
+ } else {
|
|
|
171
|
+ responseData = string(data)
|
|
|
172
|
+ }
|
|
|
173
|
+ if err = json.Unmarshal(message.Data, &response); err != nil {
|
|
|
174
|
+ log.Error(err)
|
|
|
175
|
+ return
|
|
|
176
|
+ }
|
|
|
177
|
+ log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, request, responseData))
|
|
|
178
|
+ return
|
|
|
179
|
+}
|
|
|
180
|
+
|
|
|
181
|
+/*NewApproveInstance 新增审批实例*/
|
|
|
182
|
+type NewApproveInstanceRequest struct {
|
|
|
183
|
+ Approves []Approve `json:"approves"` //审批节点列表
|
|
|
184
|
+ CompanyId int64 `json:"companyId"` //公司id
|
|
|
185
|
+ Approver string `json:"approver"` //提交人
|
|
|
186
|
+ Uid int64 `json:"uid"` //提交人id
|
|
|
187
|
+ Sign string `json:"sign"` //标识 ORDER-订单 ELSERK-其他入库 CHANCE-机会
|
|
|
188
|
+ Type int `json:"type"` //1-新增 2-编辑
|
|
|
189
|
+ RelativeId int64 `json:"relativeId"` //关联id
|
|
|
190
|
+
|
|
|
191
|
+}
|
|
|
192
|
+type NewApproveInstanceResponse struct {
|
|
|
193
|
+ protocol.ErrorCode
|
|
|
194
|
+ Data []string `json:"data"`
|
|
|
195
|
+}
|
|
|
196
|
+
|
|
|
197
|
+//审批节点
|
|
|
198
|
+type Approve struct {
|
|
|
199
|
+ ApproveWay int `json:"approveWay"` //审批方式 1 会签 2 或签 3 发起人从角色成员中自选
|
|
|
200
|
+ ApproveType int `json:"approveType"` //审批类型 1 业务区域负责人 2 指定成员 3 角色
|
|
|
201
|
+ ApproveUsers []ApproveUsers `json:"approveUsers"` //审批人
|
|
|
202
|
+}
|
|
|
203
|
+
|
|
|
204
|
+//审批人
|
|
|
205
|
+type ApproveUsers struct {
|
|
|
206
|
+ Uid int64 `json:"uid"` //用户id
|
|
|
207
|
+ Name string `json:"name"` //用户名
|
|
|
208
|
+ IsDefault int `json:"isDefault"` //1 是默认 0 不是
|
|
|
209
|
+ RoleName string `json:"roleName"` //角色名/负责人
|
|
|
210
|
+ RoleId string `json:"roleId"` //角色id
|
|
|
211
|
+ ParentIds []int `json:"parentIds"`
|
|
|
212
|
+}
|
|
|
213
|
+
|
|
|
214
|
+/*ApproveItem 审批操作*/
|
|
|
215
|
+type ApproveItemRequest struct {
|
|
|
216
|
+ RelativeId int64 `json:"relativeId"` //关联id
|
|
|
217
|
+ Type int `json:"type"` //审批类型 2 同意 3 驳回 4 撤回 5 直接提交
|
|
|
218
|
+ Suggestion string `json:"suggestion"` //原因/建议
|
|
|
219
|
+ Sign string `json:"sign"` //CHANCE
|
|
|
220
|
+ ApproveType int `json:"approveType"` //1-新增(订单用新增) 2-编辑
|
|
|
221
|
+ Uid int64 `json:"uid"` //用户id
|
|
|
222
|
+}
|
|
|
223
|
+type ApproveItemResponse struct {
|
|
|
224
|
+ Status int `json:"status"` //状态1-待确认2-已确认3-已驳回4-已撤回
|
|
|
225
|
+ ApproveStatus int `json:"approveStatus"` //审批状态0 待审批 1 审批中 2 同意 3 驳回 4 提交订单 5 已被其他人处理 (0这个状态不存在审批后)
|
|
|
226
|
+ IsApprove int `json:"isApprove"` //是否需要审批 1是 0 否
|
|
|
227
|
+}
|
|
|
228
|
+
|
|
|
229
|
+/*ApproveIntegrate 审核列表*/
|
|
|
230
|
+type ApproveIntegrateRequest struct {
|
|
|
231
|
+}
|
|
|
232
|
+type ApproveIntegrateResponse struct {
|
|
|
233
|
+} |