正在显示
5 个修改的文件
包含
313 行增加
和
7 行删除
@@ -3,6 +3,7 @@ package controllers | @@ -3,6 +3,7 @@ package controllers | ||
3 | import ( | 3 | import ( |
4 | "encoding/json" | 4 | "encoding/json" |
5 | "oppmg/common/log" | 5 | "oppmg/common/log" |
6 | + "oppmg/models" | ||
6 | "oppmg/protocol" | 7 | "oppmg/protocol" |
7 | "oppmg/services/audit" | 8 | "oppmg/services/audit" |
8 | ) | 9 | ) |
@@ -42,6 +43,58 @@ func (this *TemplateController) TemplateAdd() { | @@ -42,6 +43,58 @@ func (this *TemplateController) TemplateAdd() { | ||
42 | msg = m | 43 | msg = m |
43 | return | 44 | return |
44 | } | 45 | } |
46 | + { | ||
47 | + //审批人配置 | ||
48 | + v := request.AuditFlowConfig.NoApprover | ||
49 | + if !(v == models.NoApproverPass || v == models.NoApproverToAdmin) { | ||
50 | + msg = protocol.BadRequestParam("10068") | ||
51 | + return | ||
52 | + } | ||
53 | + if len(request.AuditFlowConfig.ProcessConfig) == 0 { | ||
54 | + msg = protocol.BadRequestParam("10069") | ||
55 | + return | ||
56 | + } | ||
57 | + var count int | ||
58 | + for i := range request.AuditFlowConfig.ProcessConfig { | ||
59 | + config := request.AuditFlowConfig.ProcessConfig[i] | ||
60 | + if !(config.ApproveType == models.AuditByDepartmentor || config.ApproveType == models.AuditByUser || config.ApproveType == models.AuditByRole) { | ||
61 | + msg = protocol.BadRequestParam("10171") | ||
62 | + return | ||
63 | + } | ||
64 | + if !(config.AcitonType == models.ActionTypeOr || config.AcitonType == models.ActionTypeAnd) { | ||
65 | + msg = protocol.BadRequestParam("10172") | ||
66 | + return | ||
67 | + } | ||
68 | + if config.ApproveType == models.AuditByUser { | ||
69 | + if len(config.ToUser) == 0 { | ||
70 | + msg = protocol.BadRequestParam("10170") | ||
71 | + return | ||
72 | + } | ||
73 | + if len(config.ToUser) > 10 { | ||
74 | + msg = protocol.BadRequestParam("10174") | ||
75 | + return | ||
76 | + } | ||
77 | + } | ||
78 | + if config.ApproveType == models.AuditByRole { | ||
79 | + if len(config.ToRole) == 0 { | ||
80 | + msg = protocol.BadRequestParam("10173") | ||
81 | + return | ||
82 | + } | ||
83 | + if len(config.ToRole) > 1 { | ||
84 | + msg = protocol.BadRequestParam("10175") | ||
85 | + return | ||
86 | + } | ||
87 | + } | ||
88 | + if config.ProcessType == models.FlowTypeNormal { | ||
89 | + count++ | ||
90 | + if count > 1 { | ||
91 | + msg = protocol.BadRequestParam("10176") | ||
92 | + return | ||
93 | + } | ||
94 | + } | ||
95 | + } | ||
96 | + } | ||
97 | + | ||
45 | rsp, err := audit.TemplateAdd(uid, companyId, request) | 98 | rsp, err := audit.TemplateAdd(uid, companyId, request) |
46 | msg = protocol.NewReturnResponse(rsp, err) | 99 | msg = protocol.NewReturnResponse(rsp, err) |
47 | return | 100 | return |
models/audit_flow_config.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "fmt" | ||
5 | + "time" | ||
6 | + | ||
7 | + "github.com/astaxie/beego/orm" | ||
8 | +) | ||
9 | + | ||
10 | +type AuditFlowConfig struct { | ||
11 | + Id int `orm:"column(id);auto" description:"唯一编号"` | ||
12 | + AuditTemplateId int64 `orm:"column(audit_template_id)" description:"表audit_template.id 所属审批模板编号"` | ||
13 | + AuditGroupId int64 `orm:"column(audit_group_id)" description:"审核组id (同一个审批批次)"` | ||
14 | + Level int `orm:"column(level)" description:"审批层级顺序,审批步骤 第几步"` | ||
15 | + AuditFlowType int `orm:"column(audit_flow_type)" description:"审核流类型 1.部门长 2.指定成员 3.指定角色"` | ||
16 | + FromSpecialUser string `orm:"column(from_special_user);size(500)" description:"特殊指定的审批单发起人 json [ ]"` | ||
17 | + ToRole string `orm:"column(to_role);null" description:"指定角色"` | ||
18 | + ToUser string `orm:"column(to_user);null" description:"指定人"` | ||
19 | + FlowType int `orm:"column(flow_type)" description:"审批类型 1:正常审核 2:特殊审核"` | ||
20 | + ActionType int `orm:"column(action_type)" description:"审批执行方式【1:or】【2:and】"` | ||
21 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
22 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
23 | + ConfigData string `orm:"column(config_data);null" description:"配置数据-冗余"` | ||
24 | +} | ||
25 | + | ||
26 | +//审核对象 | ||
27 | +const ( | ||
28 | + AuditByDepartmentor = iota + 1 //部门长 | ||
29 | + AuditByUser //指定用户 | ||
30 | + AuditByRole //指定角色 | ||
31 | + //AuditBySpecailUser //特殊人员 | ||
32 | +) | ||
33 | + | ||
34 | +//审核方式 | ||
35 | +const ( | ||
36 | + ActionTypeOr = 1 | ||
37 | + ActionTypeAnd = 2 | ||
38 | +) | ||
39 | + | ||
40 | +//审核类型 | ||
41 | +const ( | ||
42 | + FlowTypeNormal = iota + 1 //正常审核流程 | ||
43 | + FlowTypeSpecail //特殊审核流程 | ||
44 | +) | ||
45 | + | ||
46 | +//审核人为空 | ||
47 | +const ( | ||
48 | + NoApproverPass = 1 //自动通过 | ||
49 | + NoApproverToAdmin = 2 //转交给公司管理员 | ||
50 | +) | ||
51 | + | ||
52 | +var ( | ||
53 | + DeleteAuditFlowConfigSql = "delete from audit_flow_config where audit_template_id=?" | ||
54 | +) | ||
55 | + | ||
56 | +func (t *AuditFlowConfig) TableName() string { | ||
57 | + return "audit_flow_config" | ||
58 | +} | ||
59 | + | ||
60 | +func init() { | ||
61 | + orm.RegisterModel(new(AuditFlowConfig)) | ||
62 | +} | ||
63 | + | ||
64 | +// AddAuditFlowConfig insert a new AuditFlowConfig into database and returns | ||
65 | +// last inserted Id on success. | ||
66 | +func AddAuditFlowConfig(m *AuditFlowConfig) (id int64, err error) { | ||
67 | + o := orm.NewOrm() | ||
68 | + id, err = o.Insert(m) | ||
69 | + return | ||
70 | +} | ||
71 | + | ||
72 | +// GetAuditFlowConfigById retrieves AuditFlowConfig by Id. Returns error if | ||
73 | +// Id doesn't exist | ||
74 | +func GetAuditFlowConfigById(id int) (v *AuditFlowConfig, err error) { | ||
75 | + o := orm.NewOrm() | ||
76 | + v = &AuditFlowConfig{Id: id} | ||
77 | + if err = o.Read(v); err == nil { | ||
78 | + return v, nil | ||
79 | + } | ||
80 | + return nil, err | ||
81 | +} | ||
82 | + | ||
83 | +// UpdateAuditFlowConfig updates AuditFlowConfig by Id and returns error if | ||
84 | +// the record to be updated doesn't exist | ||
85 | +func UpdateAuditFlowConfigById(m *AuditFlowConfig) (err error) { | ||
86 | + o := orm.NewOrm() | ||
87 | + v := AuditFlowConfig{Id: m.Id} | ||
88 | + // ascertain id exists in the database | ||
89 | + if err = o.Read(&v); err == nil { | ||
90 | + var num int64 | ||
91 | + if num, err = o.Update(m); err == nil { | ||
92 | + fmt.Println("Number of records updated in database:", num) | ||
93 | + } | ||
94 | + } | ||
95 | + return | ||
96 | +} | ||
97 | + | ||
98 | +// DeleteAuditFlowConfig deletes AuditFlowConfig by Id and returns error if | ||
99 | +// the record to be deleted doesn't exist | ||
100 | +func DeleteAuditFlowConfig(id int) (err error) { | ||
101 | + o := orm.NewOrm() | ||
102 | + v := AuditFlowConfig{Id: id} | ||
103 | + // ascertain id exists in the database | ||
104 | + if err = o.Read(&v); err == nil { | ||
105 | + var num int64 | ||
106 | + if num, err = o.Delete(&AuditFlowConfig{Id: id}); err == nil { | ||
107 | + fmt.Println("Number of records deleted in database:", num) | ||
108 | + } | ||
109 | + } | ||
110 | + return | ||
111 | +} | ||
112 | + | ||
113 | +func GetAuditFlowConfig(id int64) ([]*AuditFlowConfig, error) { | ||
114 | + o := orm.NewOrm() | ||
115 | + var ( | ||
116 | + err error | ||
117 | + result []*AuditFlowConfig | ||
118 | + ) | ||
119 | + _, err = o.QueryTable(&AuditFlowConfig{}). | ||
120 | + Filter("audit_template_id", id). | ||
121 | + All(&result) | ||
122 | + return result, err | ||
123 | +} |
@@ -79,8 +79,9 @@ func (input ValidateInputRedio) ValidateConfig() error { | @@ -79,8 +79,9 @@ func (input ValidateInputRedio) ValidateConfig() error { | ||
79 | /***********审核模板管理**********/ | 79 | /***********审核模板管理**********/ |
80 | /*TemplateAdd */ | 80 | /*TemplateAdd */ |
81 | type TemplateAddRequest struct { | 81 | type TemplateAddRequest struct { |
82 | - Template Template `json:"template"` | ||
83 | - Example string `json:"example"` //示例 | 82 | + Template Template `json:"template"` |
83 | + Example string `json:"example"` //示例 | ||
84 | + AuditFlowConfig AuditFlowConfig `json:"audit_flow_config"` | ||
84 | } | 85 | } |
85 | type TemplateAddResponse struct { | 86 | type TemplateAddResponse struct { |
86 | } | 87 | } |
@@ -95,10 +96,25 @@ type Template struct { | @@ -95,10 +96,25 @@ type Template struct { | ||
95 | InputList []*InputElement `json:"inputList" valid:"Required;"` | 96 | InputList []*InputElement `json:"inputList" valid:"Required;"` |
96 | } | 97 | } |
97 | 98 | ||
99 | +type AuditFlowConfig struct { | ||
100 | + NoApprover int `json:"no_approver" valid:"Required;"` | ||
101 | + ProcessConfig []ProcessConfig `json:"process_config"` //创建时 0 | ||
102 | +} | ||
103 | +type ProcessConfig struct { | ||
104 | + ApproveType int `json:"approve_type"` //1.部门长 2 指定成员 3.指定角色 | ||
105 | + ProcessType int `json:"process_type"` | ||
106 | + AcitonType int `json:"aciton_type"` | ||
107 | + GroupId int `json:"group_id"` //分组id | ||
108 | + FromSpecialUser []VisibleObject `json:"from_special_user"` | ||
109 | + ToRole []VisibleObject `json:"to_role"` | ||
110 | + ToUser []VisibleObject `json:"to_user"` | ||
111 | +} | ||
112 | + | ||
98 | /*TemplateUpdate */ | 113 | /*TemplateUpdate */ |
99 | type TemplateUpdateRequest struct { | 114 | type TemplateUpdateRequest struct { |
100 | - Template Template `json:"template"` | ||
101 | - Example string `json:"example"` //示例` | 115 | + Template Template `json:"template"` |
116 | + Example string `json:"example"` //示例` | ||
117 | + AuditFlowConfig AuditFlowConfig `json:"audit_flow_config"` | ||
102 | } | 118 | } |
103 | type TemplateUpdateResponse struct { | 119 | type TemplateUpdateResponse struct { |
104 | } | 120 | } |
@@ -162,8 +178,9 @@ type TemplateGetRequest struct { | @@ -162,8 +178,9 @@ type TemplateGetRequest struct { | ||
162 | Id int `json:"id" valid:"Required"` | 178 | Id int `json:"id" valid:"Required"` |
163 | } | 179 | } |
164 | type TemplateGetResponse struct { | 180 | type TemplateGetResponse struct { |
165 | - Template Template `json:"template"` | ||
166 | - Example string `json:"example"` //示例` | 181 | + Template Template `json:"template"` |
182 | + Example string `json:"example"` //示例` | ||
183 | + AuditFlowConfig AuditFlowConfig `json:"audit_flow_config"` | ||
167 | } | 184 | } |
168 | 185 | ||
169 | /*TemplateEditSort */ | 186 | /*TemplateEditSort */ |
@@ -64,6 +64,15 @@ var errmessge ErrorMap = map[string]string{ | @@ -64,6 +64,15 @@ var errmessge ErrorMap = map[string]string{ | ||
64 | "10064": "编码已存在", | 64 | "10064": "编码已存在", |
65 | "10065": "编码长度最多6个字符", | 65 | "10065": "编码长度最多6个字符", |
66 | "10067": "一级分类不存在", | 66 | "10067": "一级分类不存在", |
67 | + "10068": "审核人为空参数有误", | ||
68 | + "10069": "未设置审核人", | ||
69 | + "10170": "请选择指定成员", | ||
70 | + "10171": "请选择审批人类别", | ||
71 | + "10172": "请选择审批方式", | ||
72 | + "10173": "请选择指定角色", | ||
73 | + "10174": "人数不能超过10个", | ||
74 | + "10175": "请选择一个角色", | ||
75 | + "10176": "至多添加一个审批人", | ||
67 | //公司相关 | 76 | //公司相关 |
68 | "12001": "未找到公司信息", | 77 | "12001": "未找到公司信息", |
69 | 78 |
@@ -45,7 +45,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | @@ -45,7 +45,7 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | ||
45 | Doc: request.Template.Doc, | 45 | Doc: request.Template.Doc, |
46 | Icon: request.Template.Icon, | 46 | Icon: request.Template.Icon, |
47 | Code: request.Template.Code, | 47 | Code: request.Template.Code, |
48 | - NoApprover: 1, //TODO:配置 | 48 | + NoApprover: int8(request.AuditFlowConfig.NoApprover), //TODO:配置 |
49 | SortNum: 0, | 49 | SortNum: 0, |
50 | VisibleType: int8(0), | 50 | VisibleType: int8(0), |
51 | EnableStatus: 1, | 51 | EnableStatus: 1, |
@@ -82,11 +82,61 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | @@ -82,11 +82,61 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | ||
82 | } | 82 | } |
83 | } | 83 | } |
84 | //审核配置 | 84 | //审核配置 |
85 | + { | ||
86 | + //删除旧的配置 | ||
87 | + if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFlowConfigSql, template.Id); err != nil { | ||
88 | + log.Error(err.Error()) | ||
89 | + orm.Rollback() | ||
90 | + return | ||
91 | + } | ||
92 | + //插入新的审批配置 | ||
93 | + var normalLevel int = 1 | ||
94 | + for i := range request.AuditFlowConfig.ProcessConfig { | ||
95 | + config := request.AuditFlowConfig.ProcessConfig[i] | ||
96 | + flowConfig := &models.AuditFlowConfig{ | ||
97 | + AuditFlowType: config.ProcessType, | ||
98 | + } | ||
99 | + if config.ProcessType == models.FlowTypeNormal { | ||
100 | + flowConfig.Level = normalLevel | ||
101 | + normalLevel++ | ||
102 | + } else { | ||
103 | + flowConfig.Level = 1 | ||
104 | + flowConfig.FromSpecialUser = jsonAssertMarsh(getIdsFrom(config.FromSpecialUser)) | ||
105 | + } | ||
106 | + flowConfig.AuditTemplateId = templateId | ||
107 | + flowConfig.ToRole = jsonAssertMarsh(getIdsFrom(config.ToRole)) | ||
108 | + flowConfig.ToUser = jsonAssertMarsh(getIdsFrom(config.ToUser)) | ||
109 | + flowConfig.ActionType = config.AcitonType | ||
110 | + flowConfig.CreateAt = time.Now() | ||
111 | + flowConfig.AuditGroupId = int64(config.GroupId) | ||
112 | + flowConfig.ConfigData = jsonAssertMarsh(config) | ||
113 | + if _, err = orm.Insert(flowConfig); err != nil { | ||
114 | + log.Error(err.Error()) | ||
115 | + orm.Rollback() | ||
116 | + return | ||
117 | + } | ||
118 | + } | ||
119 | + } | ||
85 | 120 | ||
86 | orm.Commit() | 121 | orm.Commit() |
87 | rsp = &protocol.TemplateAddResponse{} | 122 | rsp = &protocol.TemplateAddResponse{} |
88 | return | 123 | return |
89 | } | 124 | } |
125 | +func jsonAssertMarsh(v interface{}) string { | ||
126 | + if data, e := json.Marshal(v); e != nil { | ||
127 | + log.Error(fmt.Sprintf("%v %v", e.Error(), v)) | ||
128 | + return "" | ||
129 | + } else { | ||
130 | + return string(data) | ||
131 | + } | ||
132 | +} | ||
133 | + | ||
134 | +func getIdsFrom(v []protocol.VisibleObject) (ids []int) { | ||
135 | + for i := range v { | ||
136 | + ids = append(ids, v[i].Id) | ||
137 | + } | ||
138 | + return | ||
139 | +} | ||
90 | 140 | ||
91 | //模板更新 | 141 | //模板更新 |
92 | func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) { | 142 | func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateRequest) (rsp *protocol.TemplateUpdateResponse, err error) { |
@@ -144,6 +194,42 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques | @@ -144,6 +194,42 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques | ||
144 | } | 194 | } |
145 | } | 195 | } |
146 | //审核配置 | 196 | //审核配置 |
197 | + //审核配置 | ||
198 | + { | ||
199 | + //删除旧的配置 | ||
200 | + if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFlowConfigSql, template.Id); err != nil { | ||
201 | + log.Error(err.Error()) | ||
202 | + orm.Rollback() | ||
203 | + return | ||
204 | + } | ||
205 | + //插入新的审批配置 | ||
206 | + var normalLevel int = 1 | ||
207 | + for i := range request.AuditFlowConfig.ProcessConfig { | ||
208 | + config := request.AuditFlowConfig.ProcessConfig[i] | ||
209 | + flowConfig := &models.AuditFlowConfig{ | ||
210 | + AuditFlowType: config.ProcessType, | ||
211 | + } | ||
212 | + if config.ProcessType == models.FlowTypeNormal { | ||
213 | + flowConfig.Level = normalLevel | ||
214 | + normalLevel++ | ||
215 | + } else { | ||
216 | + flowConfig.Level = 1 | ||
217 | + flowConfig.FromSpecialUser = jsonAssertMarsh(getIdsFrom(config.FromSpecialUser)) | ||
218 | + } | ||
219 | + flowConfig.AuditTemplateId = template.Id | ||
220 | + flowConfig.ToRole = jsonAssertMarsh(getIdsFrom(config.ToRole)) | ||
221 | + flowConfig.ToUser = jsonAssertMarsh(getIdsFrom(config.ToUser)) | ||
222 | + flowConfig.ActionType = config.AcitonType | ||
223 | + flowConfig.CreateAt = time.Now() | ||
224 | + flowConfig.AuditGroupId = int64(config.GroupId) | ||
225 | + flowConfig.ConfigData = jsonAssertMarsh(config) | ||
226 | + if _, err = orm.Insert(flowConfig); err != nil { | ||
227 | + log.Error(err.Error()) | ||
228 | + orm.Rollback() | ||
229 | + return | ||
230 | + } | ||
231 | + } | ||
232 | + } | ||
147 | 233 | ||
148 | orm.Commit() | 234 | orm.Commit() |
149 | rsp = &protocol.TemplateUpdateResponse{} | 235 | rsp = &protocol.TemplateUpdateResponse{} |
@@ -323,6 +409,7 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs | @@ -323,6 +409,7 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs | ||
323 | var ( | 409 | var ( |
324 | template *models.AuditTemplate | 410 | template *models.AuditTemplate |
325 | auditForm []*models.AuditForm | 411 | auditForm []*models.AuditForm |
412 | + configs []*models.AuditFlowConfig | ||
326 | ) | 413 | ) |
327 | rsp = &protocol.TemplateGetResponse{} | 414 | rsp = &protocol.TemplateGetResponse{} |
328 | if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil { | 415 | if template, err = models.GetAuditTemplateById(int64(request.Id)); err != nil { |
@@ -357,6 +444,23 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs | @@ -357,6 +444,23 @@ func TemplateGet(uid, companyId int64, request *protocol.TemplateGetRequest) (rs | ||
357 | SectionType: input.Section, | 444 | SectionType: input.Section, |
358 | }) | 445 | }) |
359 | } | 446 | } |
447 | + if configs, err = models.GetAuditFlowConfig(template.Id); err != nil { | ||
448 | + log.Error("template:%v %v", template.Id, err.Error()) | ||
449 | + err = nil | ||
450 | + return | ||
451 | + } | ||
452 | + rsp.AuditFlowConfig = protocol.AuditFlowConfig{ | ||
453 | + NoApprover: int(template.NoApprover), | ||
454 | + } | ||
455 | + for i := range configs { | ||
456 | + config := configs[i] | ||
457 | + var configItem protocol.ProcessConfig | ||
458 | + if e := json.Unmarshal([]byte(config.ConfigData), &configItem); e != nil { | ||
459 | + log.Error(e.Error()) | ||
460 | + continue | ||
461 | + } | ||
462 | + rsp.AuditFlowConfig.ProcessConfig = append(rsp.AuditFlowConfig.ProcessConfig, configItem) | ||
463 | + } | ||
360 | } | 464 | } |
361 | return | 465 | return |
362 | } | 466 | } |
-
请 注册 或 登录 后发表评论