正在显示
3 个修改的文件
包含
211 行增加
和
14 行删除
models/audit_check.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "time" | ||
5 | + | ||
6 | + "github.com/astaxie/beego/orm" | ||
7 | +) | ||
8 | + | ||
9 | +type AuditCheck struct { | ||
10 | + Id int64 `orm:"column(id);pk"` | ||
11 | + Pid int64 `orm:"column(pid)"` | ||
12 | + TemplateId int64 `orm:"column(template_id)" description:"模板id"` | ||
13 | + Title string `orm:"column(title);size(100)" description:"标题"` | ||
14 | + Items string `orm:"column(items)" description:"选项数据json格式"` | ||
15 | + Enable int8 `orm:"column(enable)" description:"是否有效【0:无效】【1:有效】"` | ||
16 | + CreateTime time.Time `orm:"column(create_time);type(timestamp)"` | ||
17 | +} | ||
18 | + | ||
19 | +func (t *AuditCheck) TableName() string { | ||
20 | + return "audit_check" | ||
21 | +} | ||
22 | + | ||
23 | +func init() { | ||
24 | + orm.RegisterModel(new(AuditCheck)) | ||
25 | +} | ||
26 | + | ||
27 | +//AuditCheckItems 自查内容选项 | ||
28 | +// AuditCheck 表items存储的json结构 | ||
29 | +type AuditCheckItems struct { | ||
30 | + Items []AuditCheckItem `json:"items"` | ||
31 | +} | ||
32 | + | ||
33 | +type AuditCheckItem struct { | ||
34 | + Item string `json:"item"` //选项内容 | ||
35 | + NeedOther int `json:"needOther"` //是否需填写其他的内容【1:需要】【2:不需要】 | ||
36 | +} | ||
37 | + | ||
38 | +//AuditCheck 表enable字段含义 是否有效【0:无效】【1:有效】 | ||
39 | +const ( | ||
40 | + AUDITCHECK_ENABLE_NO int8 = 0 | ||
41 | + AUDITCHECK_ENABLE_YES int8 = 1 | ||
42 | +) | ||
43 | + | ||
44 | +// AddAuditCheck insert a new AuditCheck into database and returns | ||
45 | +// last inserted Id on success. | ||
46 | +func AddAuditCheck(m *AuditCheck) (id int64, err error) { | ||
47 | + o := orm.NewOrm() | ||
48 | + id, err = o.Insert(m) | ||
49 | + return | ||
50 | +} | ||
51 | + | ||
52 | +// GetAuditCheckById retrieves AuditCheck by Id. Returns error if | ||
53 | +// Id doesn't exist | ||
54 | +func GetAuditCheckById(id int64) (v *AuditCheck, err error) { | ||
55 | + o := orm.NewOrm() | ||
56 | + v = &AuditCheck{Id: id} | ||
57 | + if err = o.Read(v); err == nil { | ||
58 | + return v, nil | ||
59 | + } | ||
60 | + return nil, err | ||
61 | +} | ||
62 | + | ||
63 | +// DeleteAuditCheck deletes AuditCheck by Id and returns error if | ||
64 | +// the record to be deleted doesn't exist | ||
65 | +// func DeleteAuditCheck(id int64) (err error) { | ||
66 | +// o := orm.NewOrm() | ||
67 | +// v := AuditCheck{Id: id} | ||
68 | +// // ascertain id exists in the database | ||
69 | +// if err = o.Read(&v); err == nil { | ||
70 | +// var num int64 | ||
71 | +// if num, err = o.Delete(&AuditCheck{Id: id}); err == nil { | ||
72 | +// fmt.Println("Number of records deleted in database:", num) | ||
73 | +// } | ||
74 | +// } | ||
75 | +// return | ||
76 | +// } | ||
77 | + | ||
78 | +func GetAuditCheckByTemplate(templateId int64) ([]AuditCheck, error) { | ||
79 | + var ( | ||
80 | + data []AuditCheck | ||
81 | + err error | ||
82 | + ) | ||
83 | + o := orm.NewOrm() | ||
84 | + _, err = o.QueryTable(&AuditCheck{}). | ||
85 | + Filter("template_id", templateId). | ||
86 | + Filter("enable", AUDITCHECK_ENABLE_YES). | ||
87 | + All(&data) | ||
88 | + if err == orm.ErrNoRows { | ||
89 | + return data, nil | ||
90 | + } | ||
91 | + if err != nil { | ||
92 | + return nil, err | ||
93 | + } | ||
94 | + return data, nil | ||
95 | +} | ||
96 | + | ||
97 | +func DeleteAuditCheckByTempelate(templateId int64, om orm.Ormer) error { | ||
98 | + var ( | ||
99 | + err error | ||
100 | + ) | ||
101 | + _, err = om.QueryTable(&AuditCheck{}). | ||
102 | + Filter("template_id", templateId). | ||
103 | + Filter("enable", AUDITCHECK_ENABLE_YES). | ||
104 | + Update(orm.Params{ | ||
105 | + "enable": AUDITCHECK_ENABLE_NO, | ||
106 | + }) | ||
107 | + return err | ||
108 | +} |
@@ -79,11 +79,21 @@ func (input ValidateInputRedio) ValidateConfig() error { | @@ -79,11 +79,21 @@ func (input ValidateInputRedio) ValidateConfig() error { | ||
79 | 79 | ||
80 | /***********审核模板管理**********/ | 80 | /***********审核模板管理**********/ |
81 | /*TemplateAdd */ | 81 | /*TemplateAdd */ |
82 | + | ||
83 | +//TemplateSelfCheck 机会模板自查内容设定 | ||
84 | +type TemplateSelfCheck struct { | ||
85 | + Id int64 `json:"id"` | ||
86 | + Pid int64 `json:"pid"` | ||
87 | + Title string `json:"title"` //标题 | ||
88 | + Child []TemplateSelfCheck `json:"child"` //下级维度 | ||
89 | +} | ||
90 | + | ||
82 | type TemplateAddRequest struct { | 91 | type TemplateAddRequest struct { |
83 | - Template Template `json:"template"` | ||
84 | - Example string `json:"example"` //示例 | ||
85 | - Videos []string `json:"videos"` //视频 | ||
86 | - AuditFlowConfig AuditFlowConfig `json:"auditFlowConfig"` | 92 | + Template Template `json:"template"` |
93 | + Example string `json:"example"` //示例 | ||
94 | + Videos []string `json:"videos"` //视频 | ||
95 | + AuditFlowConfig AuditFlowConfig `json:"auditFlowConfig"` | ||
96 | + SelfCheck []TemplateSelfCheck `json:"selfCheck"` | ||
87 | } | 97 | } |
88 | type TemplateAddResponse struct { | 98 | type TemplateAddResponse struct { |
89 | } | 99 | } |
@@ -114,10 +124,11 @@ type ProcessConfig struct { | @@ -114,10 +124,11 @@ type ProcessConfig struct { | ||
114 | 124 | ||
115 | /*TemplateUpdate */ | 125 | /*TemplateUpdate */ |
116 | type TemplateUpdateRequest struct { | 126 | type TemplateUpdateRequest struct { |
117 | - Template Template `json:"template"` | ||
118 | - Example string `json:"example"` //示例` | ||
119 | - Videos []string `json:"videos"` //视频 | ||
120 | - AuditFlowConfig AuditFlowConfig `json:"auditFlowConfig"` | 127 | + Template Template `json:"template"` |
128 | + Example string `json:"example"` //示例` | ||
129 | + Videos []string `json:"videos"` //视频 | ||
130 | + AuditFlowConfig AuditFlowConfig `json:"auditFlowConfig"` | ||
131 | + SelfCheck []TemplateSelfCheck `json:"selfCheck"` //自查内容 | ||
121 | } | 132 | } |
122 | type TemplateUpdateResponse struct { | 133 | type TemplateUpdateResponse struct { |
123 | } | 134 | } |
@@ -181,10 +192,11 @@ type TemplateGetRequest struct { | @@ -181,10 +192,11 @@ type TemplateGetRequest struct { | ||
181 | Id int `json:"id" valid:"Required"` | 192 | Id int `json:"id" valid:"Required"` |
182 | } | 193 | } |
183 | type TemplateGetResponse struct { | 194 | type TemplateGetResponse struct { |
184 | - Template Template `json:"template"` | ||
185 | - Example string `json:"example"` //示例` | ||
186 | - Videos []string `json:"videos"` //视频 | ||
187 | - AuditFlowConfig AuditFlowConfig `json:"auditFlowConfig"` | 195 | + Template Template `json:"template"` |
196 | + Example string `json:"example"` //示例` | ||
197 | + Videos []string `json:"videos"` //视频 | ||
198 | + AuditFlowConfig AuditFlowConfig `json:"auditFlowConfig"` | ||
199 | + SelfCheck []TemplateSelfCheck `json:"selfCheck"` //自查内容 | ||
188 | } | 200 | } |
189 | 201 | ||
190 | /*TemplateEditSort */ | 202 | /*TemplateEditSort */ |
@@ -8,6 +8,7 @@ import ( | @@ -8,6 +8,7 @@ import ( | ||
8 | "oppmg/models" | 8 | "oppmg/models" |
9 | "oppmg/protocol" | 9 | "oppmg/protocol" |
10 | "oppmg/utils" | 10 | "oppmg/utils" |
11 | + "oppmg/utils/idworker" | ||
11 | "strings" | 12 | "strings" |
12 | "time" | 13 | "time" |
13 | 14 | ||
@@ -129,11 +130,82 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | @@ -129,11 +130,82 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | ||
129 | } | 130 | } |
130 | } | 131 | } |
131 | } | 132 | } |
132 | - | 133 | + //添加自查内容 |
134 | + err = addSelfCheckData(templateId, request.SelfCheck, orm) | ||
135 | + if err != nil { | ||
136 | + log.Error("模板设置,添加自查内容失败,err:%s", err) | ||
137 | + orm.Rollback() | ||
138 | + return nil, protocol.NewErrWithMessage("1") | ||
139 | + } | ||
133 | orm.Commit() | 140 | orm.Commit() |
134 | rsp = &protocol.TemplateAddResponse{} | 141 | rsp = &protocol.TemplateAddResponse{} |
135 | return | 142 | return |
136 | } | 143 | } |
144 | + | ||
145 | +//SetSelfCheckData 机会模板设置-自查内容设置 | ||
146 | +func addSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error { | ||
147 | + var ( | ||
148 | + addSelfCheck []models.AuditCheck | ||
149 | + err error | ||
150 | + ) | ||
151 | + defaultItem := models.AuditCheckItems{ | ||
152 | + Items: []models.AuditCheckItem{ | ||
153 | + models.AuditCheckItem{Item: "是", NeedOther: 0}, | ||
154 | + models.AuditCheckItem{Item: "否", NeedOther: 1}, | ||
155 | + models.AuditCheckItem{Item: "不清楚", NeedOther: 0}, | ||
156 | + }, | ||
157 | + } | ||
158 | + defaultItemJson, _ := json.Marshal(defaultItem) | ||
159 | + nowTime := time.Now() | ||
160 | + for _, v := range data { | ||
161 | + mId := idworker.NextId() | ||
162 | + m := models.AuditCheck{ | ||
163 | + Id: mId, | ||
164 | + Pid: 0, | ||
165 | + TemplateId: templateId, | ||
166 | + Title: v.Title, | ||
167 | + Enable: models.AUDITCHECK_ENABLE_YES, | ||
168 | + CreateTime: nowTime, | ||
169 | + Items: string(defaultItemJson), | ||
170 | + } | ||
171 | + addSelfCheck = append(addSelfCheck, m) | ||
172 | + if len(v.Child) > 0 { | ||
173 | + for _, vv := range v.Child { | ||
174 | + childId := idworker.NextId() | ||
175 | + childDdata := models.AuditCheck{ | ||
176 | + Id: childId, | ||
177 | + Pid: mId, | ||
178 | + TemplateId: templateId, | ||
179 | + Title: vv.Title, | ||
180 | + Enable: models.AUDITCHECK_ENABLE_YES, | ||
181 | + CreateTime: nowTime, | ||
182 | + Items: string(defaultItemJson), | ||
183 | + } | ||
184 | + addSelfCheck = append(addSelfCheck, childDdata) | ||
185 | + } | ||
186 | + } | ||
187 | + } | ||
188 | + _, err = om.InsertMulti(10, addSelfCheck) | ||
189 | + return err | ||
190 | +} | ||
191 | + | ||
192 | +func editSelfCheckData(templateId int64, data []protocol.TemplateSelfCheck, om orm2.Ormer) error { | ||
193 | + var ( | ||
194 | + err error | ||
195 | + ) | ||
196 | + err = models.DeleteAuditCheckByTempelate(templateId, om) | ||
197 | + if err != nil { | ||
198 | + log.Error("软删除audit_check数据失败,err;%s", err) | ||
199 | + return err | ||
200 | + } | ||
201 | + err = addSelfCheckData(templateId, data, om) | ||
202 | + if err != nil { | ||
203 | + log.Error("添加audit_check数据失败,err:%s", err) | ||
204 | + return err | ||
205 | + } | ||
206 | + return nil | ||
207 | +} | ||
208 | + | ||
137 | func jsonAssertMarsh(v interface{}) string { | 209 | func jsonAssertMarsh(v interface{}) string { |
138 | if data, e := json.Marshal(v); e != nil { | 210 | if data, e := json.Marshal(v); e != nil { |
139 | log.Error(fmt.Sprintf("%v %v", e.Error(), v)) | 211 | log.Error(fmt.Sprintf("%v %v", e.Error(), v)) |
@@ -255,7 +327,12 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques | @@ -255,7 +327,12 @@ func TemplateUpdate(uid, companyId int64, request *protocol.TemplateUpdateReques | ||
255 | } | 327 | } |
256 | } | 328 | } |
257 | } | 329 | } |
258 | - | 330 | + err = editSelfCheckData(template.Id, request.SelfCheck, orm) |
331 | + if err != nil { | ||
332 | + log.Error("更新audit_check数据失败:err:%s", err) | ||
333 | + orm.Rollback() | ||
334 | + return rsp, protocol.NewErrWithMessage("1") | ||
335 | + } | ||
259 | orm.Commit() | 336 | orm.Commit() |
260 | rsp = &protocol.TemplateUpdateResponse{} | 337 | rsp = &protocol.TemplateUpdateResponse{} |
261 | return | 338 | return |
-
请 注册 或 登录 后发表评论