正在显示
7 个修改的文件
包含
160 行增加
和
52 行删除
| @@ -34,11 +34,6 @@ func (this *TemplateController) TemplateAdd() { | @@ -34,11 +34,6 @@ func (this *TemplateController) TemplateAdd() { | ||
| 34 | msg = protocol.BadRequestParam("1") | 34 | msg = protocol.BadRequestParam("1") |
| 35 | return | 35 | return |
| 36 | } | 36 | } |
| 37 | - //if !(request.Type == 1 || request.Type == 2) { | ||
| 38 | - // msg = protocol.BadRequestParam("1") | ||
| 39 | - // log.Error("type error :%v", request.Type) | ||
| 40 | - // return | ||
| 41 | - //} | ||
| 42 | if b, m := this.Valid(request); !b { | 37 | if b, m := this.Valid(request); !b { |
| 43 | msg = m | 38 | msg = m |
| 44 | return | 39 | return |
| @@ -52,10 +47,6 @@ func (this *TemplateController) TemplateAdd() { | @@ -52,10 +47,6 @@ func (this *TemplateController) TemplateAdd() { | ||
| 52 | return | 47 | return |
| 53 | } | 48 | } |
| 54 | { | 49 | { |
| 55 | - //名称不能超过20字 | ||
| 56 | - //字段只能10个字段 | ||
| 57 | - } | ||
| 58 | - { | ||
| 59 | //审批人配置 | 50 | //审批人配置 |
| 60 | v := request.AuditFlowConfig.NoApprover | 51 | v := request.AuditFlowConfig.NoApprover |
| 61 | if !(v == models.NoApproverPass || v == models.NoApproverToAdmin) { | 52 | if !(v == models.NoApproverPass || v == models.NoApproverToAdmin) { |
| @@ -66,47 +57,18 @@ func (this *TemplateController) TemplateAdd() { | @@ -66,47 +57,18 @@ func (this *TemplateController) TemplateAdd() { | ||
| 66 | msg = protocol.BadRequestParam("10069") | 57 | msg = protocol.BadRequestParam("10069") |
| 67 | return | 58 | return |
| 68 | } | 59 | } |
| 69 | - var count int | ||
| 70 | - for i := range request.AuditFlowConfig.ProcessConfig { | ||
| 71 | - config := request.AuditFlowConfig.ProcessConfig[i] | ||
| 72 | - if !(config.ApproveType == models.AuditByDepartmentor || config.ApproveType == models.AuditByUser || config.ApproveType == models.AuditByRole) { | ||
| 73 | - msg = protocol.BadRequestParam("10171") | ||
| 74 | - return | ||
| 75 | - } | ||
| 76 | - if !(config.AcitonType == models.ActionTypeOr || config.AcitonType == models.ActionTypeAnd) { | ||
| 77 | - msg = protocol.BadRequestParam("10172") | ||
| 78 | - return | ||
| 79 | - } | ||
| 80 | - if config.ApproveType == models.AuditByUser { | ||
| 81 | - if len(config.ToUser) == 0 { | ||
| 82 | - msg = protocol.BadRequestParam("10170") | ||
| 83 | - return | ||
| 84 | } | 60 | } |
| 85 | - if len(config.ToUser) > 10 { | ||
| 86 | - msg = protocol.BadRequestParam("10174") | ||
| 87 | - return | ||
| 88 | - } | ||
| 89 | - } | ||
| 90 | - if config.ApproveType == models.AuditByRole { | ||
| 91 | - if len(config.ToRole) == 0 { | ||
| 92 | - msg = protocol.BadRequestParam("10173") | ||
| 93 | - return | ||
| 94 | - } | ||
| 95 | - if len(config.ToRole) > 1 { | ||
| 96 | - msg = protocol.BadRequestParam("10175") | 61 | + { |
| 62 | + if msg = audit.ValidFormList(request.Template.InputList); msg.Errno != 0 { | ||
| 63 | + log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg) | ||
| 97 | return | 64 | return |
| 98 | } | 65 | } |
| 99 | - } | ||
| 100 | - if config.ProcessType == models.FlowTypeNormal { | ||
| 101 | - count++ | ||
| 102 | - if count > 1 { | ||
| 103 | - msg = protocol.BadRequestParam("10176") | 66 | + |
| 67 | + if msg = audit.ValidAuditFlowConfig(request.AuditFlowConfig); msg.Errno != 0 { | ||
| 68 | + log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg) | ||
| 104 | return | 69 | return |
| 105 | } | 70 | } |
| 106 | } | 71 | } |
| 107 | - } | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | rsp, err := audit.TemplateAdd(uid, companyId, request) | 72 | rsp, err := audit.TemplateAdd(uid, companyId, request) |
| 111 | msg = protocol.NewReturnResponse(rsp, err) | 73 | msg = protocol.NewReturnResponse(rsp, err) |
| 112 | return | 74 | return |
| @@ -145,6 +107,17 @@ func (this *TemplateController) TemplateUpdate() { | @@ -145,6 +107,17 @@ func (this *TemplateController) TemplateUpdate() { | ||
| 145 | msg = protocol.BadRequestParam("10272") | 107 | msg = protocol.BadRequestParam("10272") |
| 146 | return | 108 | return |
| 147 | } | 109 | } |
| 110 | + { | ||
| 111 | + if msg = audit.ValidFormList(request.Template.InputList); msg.Errno != 0 { | ||
| 112 | + log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg) | ||
| 113 | + return | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + if msg = audit.ValidAuditFlowConfig(request.AuditFlowConfig); msg.Errno != 0 { | ||
| 117 | + log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg) | ||
| 118 | + return | ||
| 119 | + } | ||
| 120 | + } | ||
| 148 | rsp, err := audit.TemplateUpdate(uid, companyId, request) | 121 | rsp, err := audit.TemplateUpdate(uid, companyId, request) |
| 149 | msg = protocol.NewReturnResponse(rsp, err) | 122 | msg = protocol.NewReturnResponse(rsp, err) |
| 150 | return | 123 | return |
| @@ -122,3 +122,12 @@ func GetAuditTemplateByName(companyId int64, name string, chanceTypeId int) (v * | @@ -122,3 +122,12 @@ func GetAuditTemplateByName(companyId int64, name string, chanceTypeId int) (v * | ||
| 122 | } | 122 | } |
| 123 | return | 123 | return |
| 124 | } | 124 | } |
| 125 | + | ||
| 126 | +func GetAuditTemplateSort(companyId int64, chanceTypeId int) (v *ChanceType, err error) { | ||
| 127 | + o := orm.NewOrm() | ||
| 128 | + sql := "select max(sort_num) sort_num from audit_template where company_id=? and chance_type_id=?" | ||
| 129 | + if err = o.Raw(sql, companyId, chanceTypeId).QueryRow(&v); err == nil { | ||
| 130 | + return | ||
| 131 | + } | ||
| 132 | + return | ||
| 133 | +} |
| @@ -110,3 +110,13 @@ func GetChanceTypeByName(companyId int64, name string) (v *ChanceType, err error | @@ -110,3 +110,13 @@ func GetChanceTypeByName(companyId int64, name string) (v *ChanceType, err error | ||
| 110 | } | 110 | } |
| 111 | return | 111 | return |
| 112 | } | 112 | } |
| 113 | + | ||
| 114 | +//获取一级分类最大序号 | ||
| 115 | +func GetChanceTypeMaxSort(companyId int64) (v *ChanceType, err error) { | ||
| 116 | + o := orm.NewOrm() | ||
| 117 | + sql := "select max(sort_num) sort_num from chance_type where company_id=?" | ||
| 118 | + if err = o.Raw(sql, companyId).QueryRow(&v); err == nil { | ||
| 119 | + return | ||
| 120 | + } | ||
| 121 | + return | ||
| 122 | +} |
| @@ -35,14 +35,18 @@ type ResponseMessage struct { | @@ -35,14 +35,18 @@ type ResponseMessage struct { | ||
| 35 | Errno int `json:"code"` | 35 | Errno int `json:"code"` |
| 36 | Errmsg string `json:"msg"` | 36 | Errmsg string `json:"msg"` |
| 37 | Data interface{} `json:"data"` | 37 | Data interface{} `json:"data"` |
| 38 | + | ||
| 39 | + OriginErrno string `json:"-"` | ||
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | func NewMessage(code string) *ResponseMessage { | 42 | func NewMessage(code string) *ResponseMessage { |
| 41 | ecode := SearchErr(code) | 43 | ecode := SearchErr(code) |
| 44 | + | ||
| 42 | rsp := &ResponseMessage{ | 45 | rsp := &ResponseMessage{ |
| 43 | Errno: transformCode(ecode.Errno), | 46 | Errno: transformCode(ecode.Errno), |
| 44 | Errmsg: ecode.Errmsg, | 47 | Errmsg: ecode.Errmsg, |
| 45 | Data: NullData, | 48 | Data: NullData, |
| 49 | + OriginErrno: code, | ||
| 46 | } | 50 | } |
| 47 | return rsp | 51 | return rsp |
| 48 | } | 52 | } |
| @@ -87,6 +87,9 @@ var errmessge ErrorMap = map[string]string{ | @@ -87,6 +87,9 @@ var errmessge ErrorMap = map[string]string{ | ||
| 87 | "10281": "请您选择的审批人员", | 87 | "10281": "请您选择的审批人员", |
| 88 | "10282": "请您选择的审批角色", | 88 | "10282": "请您选择的审批角色", |
| 89 | "10283": "特殊审批流程被审批人不可重复", | 89 | "10283": "特殊审批流程被审批人不可重复", |
| 90 | + "10284": "表单字段已经重复", | ||
| 91 | + "10285": "未设置基础内容", | ||
| 92 | + "10286": "未设置特殊审批人", | ||
| 90 | 93 | ||
| 91 | "10170": "请选择指定成员", | 94 | "10170": "请选择指定成员", |
| 92 | "10171": "请选择审批人类别", | 95 | "10171": "请选择审批人类别", |
| @@ -56,6 +56,11 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | @@ -56,6 +56,11 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs | ||
| 56 | CreateAt: time.Now(), | 56 | CreateAt: time.Now(), |
| 57 | UpdateAt: time.Now(), | 57 | UpdateAt: time.Now(), |
| 58 | } | 58 | } |
| 59 | + if t, e := models.GetAuditTemplateSort(companyId, request.Template.ChanceTypeId); e == nil { | ||
| 60 | + template.SortNum = t.SortNum + 1 | ||
| 61 | + } else { | ||
| 62 | + template.SortNum = 1 | ||
| 63 | + } | ||
| 59 | if templateId, err = orm.Insert(template); err != nil { | 64 | if templateId, err = orm.Insert(template); err != nil { |
| 60 | log.Error(err.Error()) | 65 | log.Error(err.Error()) |
| 61 | orm.Rollback() | 66 | orm.Rollback() |
| @@ -515,10 +520,18 @@ func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteReques | @@ -515,10 +520,18 @@ func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteReques | ||
| 515 | return | 520 | return |
| 516 | } | 521 | } |
| 517 | orm := orm2.NewOrm() | 522 | orm := orm2.NewOrm() |
| 523 | + orm.Begin() | ||
| 518 | if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFormBy, request.TemplateId, companyId); err != nil { | 524 | if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFormBy, request.TemplateId, companyId); err != nil { |
| 519 | log.Error(err.Error()) | 525 | log.Error(err.Error()) |
| 526 | + orm.Rollback() | ||
| 527 | + return | ||
| 528 | + } | ||
| 529 | + if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFlowConfigSql, request.TemplateId); err != nil { | ||
| 530 | + log.Error(err.Error()) | ||
| 531 | + orm.Rollback() | ||
| 520 | return | 532 | return |
| 521 | } | 533 | } |
| 534 | + orm.Commit() | ||
| 522 | rsp = &protocol.TemplateDeleteResponse{} | 535 | rsp = &protocol.TemplateDeleteResponse{} |
| 523 | return | 536 | return |
| 524 | } | 537 | } |
| @@ -605,6 +618,11 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe | @@ -605,6 +618,11 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe | ||
| 605 | err = protocol.NewErrWithMessage("10271") | 618 | err = protocol.NewErrWithMessage("10271") |
| 606 | return | 619 | return |
| 607 | } | 620 | } |
| 621 | + if c, e := models.GetChanceTypeMaxSort(companyId); e == nil { | ||
| 622 | + chanceType.SortNum = c.SortNum + 1 | ||
| 623 | + } else { | ||
| 624 | + chanceType.SortNum = 1 | ||
| 625 | + } | ||
| 608 | if _, err = models.AddChanceType(chanceType); err != nil { | 626 | if _, err = models.AddChanceType(chanceType); err != nil { |
| 609 | log.Error(err.Error()) | 627 | log.Error(err.Error()) |
| 610 | } | 628 | } |
| @@ -687,7 +705,7 @@ func CategoryEditSort(uid, companyId int64, request *protocol.CategoryEditSortRe | @@ -687,7 +705,7 @@ func CategoryEditSort(uid, companyId int64, request *protocol.CategoryEditSortRe | ||
| 687 | func ValidAuditFlowConfig(flowConfig protocol.AuditFlowConfig) (msg *protocol.ResponseMessage) { | 705 | func ValidAuditFlowConfig(flowConfig protocol.AuditFlowConfig) (msg *protocol.ResponseMessage) { |
| 688 | var ( | 706 | var ( |
| 689 | count int | 707 | count int |
| 690 | - specailUser map[int]int | 708 | + specailUser map[int]int = make(map[int]int) |
| 691 | ) | 709 | ) |
| 692 | msg = protocol.NewMessage("0") | 710 | msg = protocol.NewMessage("0") |
| 693 | for i := range flowConfig.ProcessConfig { | 711 | for i := range flowConfig.ProcessConfig { |
| @@ -729,18 +747,16 @@ func ValidAuditFlowConfig(flowConfig protocol.AuditFlowConfig) (msg *protocol.Re | @@ -729,18 +747,16 @@ func ValidAuditFlowConfig(flowConfig protocol.AuditFlowConfig) (msg *protocol.Re | ||
| 729 | } | 747 | } |
| 730 | if config.ProcessType == models.FlowTypeSpecail { | 748 | if config.ProcessType == models.FlowTypeSpecail { |
| 731 | if len(config.FromSpecialUser) == 0 { //特殊人为空 | 749 | if len(config.FromSpecialUser) == 0 { //特殊人为空 |
| 732 | - msg = protocol.BadRequestParam("10281") | ||
| 733 | - return | ||
| 734 | - } | ||
| 735 | - msg = ValidProcessConfig(&config) | ||
| 736 | - if msg.Errno != 0 { | 750 | + msg = protocol.BadRequestParam("10286") |
| 737 | return | 751 | return |
| 738 | } | 752 | } |
| 739 | - for i := range config.ToUser { | ||
| 740 | - u := config.ToUser[i] | 753 | + for i := range config.FromSpecialUser { |
| 754 | + u := config.FromSpecialUser[i] | ||
| 741 | if _, ok := specailUser[u.Id]; ok { | 755 | if _, ok := specailUser[u.Id]; ok { |
| 742 | msg = protocol.BadRequestParam("10283") | 756 | msg = protocol.BadRequestParam("10283") |
| 743 | return | 757 | return |
| 758 | + } else { | ||
| 759 | + specailUser[u.Id] = u.Id | ||
| 744 | } | 760 | } |
| 745 | } | 761 | } |
| 746 | } | 762 | } |
| @@ -769,3 +785,47 @@ func ValidProcessConfig(config *protocol.ProcessConfig) (msg *protocol.ResponseM | @@ -769,3 +785,47 @@ func ValidProcessConfig(config *protocol.ProcessConfig) (msg *protocol.ResponseM | ||
| 769 | } | 785 | } |
| 770 | return | 786 | return |
| 771 | } | 787 | } |
| 788 | + | ||
| 789 | +//校验表单 | ||
| 790 | +//名称不能超过20字 | ||
| 791 | +//表单项最低10个字段 | ||
| 792 | +//表单项不能重复 | ||
| 793 | +//基础表单项不能为空 | ||
| 794 | +func ValidFormList(inputs []*protocol.InputElement) (msg *protocol.ResponseMessage) { | ||
| 795 | + msg = &protocol.ResponseMessage{} | ||
| 796 | + var mapCheckRe map[string]string = make(map[string]string) | ||
| 797 | + var countBasic, countExtral int | ||
| 798 | + var countBasicRequire int | ||
| 799 | + for i := range inputs { | ||
| 800 | + input := inputs[i] | ||
| 801 | + if len([]rune(input.Label)) > 20 { | ||
| 802 | + msg = protocol.BadRequestParam("10273") | ||
| 803 | + return | ||
| 804 | + } | ||
| 805 | + key := fmt.Sprintf("%v-%v", input.SectionType, input.Label) | ||
| 806 | + if _, ok := mapCheckRe[key]; ok { | ||
| 807 | + msg = protocol.BadRequestParam("10284") | ||
| 808 | + return | ||
| 809 | + } else { | ||
| 810 | + mapCheckRe[key] = key | ||
| 811 | + } | ||
| 812 | + if input.SectionType == 1 { | ||
| 813 | + countBasic++ | ||
| 814 | + } | ||
| 815 | + if input.SectionType == 2 { | ||
| 816 | + countExtral++ | ||
| 817 | + } | ||
| 818 | + if input.SectionType == 1 && input.Required == 1 { | ||
| 819 | + countBasicRequire++ | ||
| 820 | + } | ||
| 821 | + } | ||
| 822 | + if countBasic == 0 { | ||
| 823 | + msg = protocol.BadRequestParam("10285") | ||
| 824 | + return | ||
| 825 | + } | ||
| 826 | + if countBasic >= 10 || countExtral >= 10 { | ||
| 827 | + msg = protocol.BadRequestParam("10274") | ||
| 828 | + return | ||
| 829 | + } | ||
| 830 | + return | ||
| 831 | +} |
services/audit/template_test.go
0 → 100644
| 1 | +package audit | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "oppmg/models" | ||
| 5 | + "oppmg/protocol" | ||
| 6 | + "testing" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +func Test_ValidFormList(t *testing.T) { | ||
| 10 | + input := []*protocol.InputElement{ | ||
| 11 | + //{ | ||
| 12 | + // Label:"dsaghoida", | ||
| 13 | + // SectionType:1, | ||
| 14 | + //}, | ||
| 15 | + //{ | ||
| 16 | + // Label:"dsaghoida2", | ||
| 17 | + // SectionType:1, | ||
| 18 | + //}, | ||
| 19 | + { | ||
| 20 | + Label: "dsaghoid", | ||
| 21 | + SectionType: 2, | ||
| 22 | + }, {Label: "1", SectionType: 2}, {Label: "2", SectionType: 2}, {Label: "3", SectionType: 2}, {Label: "4", SectionType: 2}, {Label: "5", SectionType: 2}, {Label: "6", SectionType: 2}, {Label: "7", SectionType: 2}, {Label: "8", SectionType: 2}, {Label: "9", SectionType: 2}, {Label: "10", SectionType: 2}, | ||
| 23 | + } | ||
| 24 | + msg := ValidFormList(input) | ||
| 25 | + if msg.Errno != 0 { | ||
| 26 | + t.Log(msg.Errno, msg.Errmsg) | ||
| 27 | + } | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func Test_ValidAuditFlowConfig(t *testing.T) { | ||
| 31 | + input := protocol.AuditFlowConfig{ | ||
| 32 | + NoApprover: 0, | ||
| 33 | + ProcessConfig: []protocol.ProcessConfig{ | ||
| 34 | + { | ||
| 35 | + ApproveType: models.AuditByRole, | ||
| 36 | + ProcessType: models.FlowTypeSpecail, | ||
| 37 | + AcitonType: models.ActionTypeAnd, | ||
| 38 | + GroupId: 1, | ||
| 39 | + FromSpecialUser: []protocol.VisibleObject{{Id: 1, Name: "1"}, {Id: 1, Name: "1"}}, | ||
| 40 | + ToUser: []protocol.VisibleObject{{Id: 1, Name: "1"}}, | ||
| 41 | + ToRole: []protocol.VisibleObject{{Id: 1, Name: "1"}}, | ||
| 42 | + }, | ||
| 43 | + }, | ||
| 44 | + } | ||
| 45 | + msg := ValidAuditFlowConfig(input) | ||
| 46 | + if msg.Errno != 0 { | ||
| 47 | + t.Log(msg.OriginErrno, msg.Errmsg) | ||
| 48 | + } | ||
| 49 | +} |
-
请 注册 或 登录 后发表评论