作者 yangfu

模板修改

... ... @@ -34,11 +34,6 @@ func (this *TemplateController) TemplateAdd() {
msg = protocol.BadRequestParam("1")
return
}
//if !(request.Type == 1 || request.Type == 2) {
// msg = protocol.BadRequestParam("1")
// log.Error("type error :%v", request.Type)
// return
//}
if b, m := this.Valid(request); !b {
msg = m
return
... ... @@ -52,10 +47,6 @@ func (this *TemplateController) TemplateAdd() {
return
}
{
//名称不能超过20字
//字段只能10个字段
}
{
//审批人配置
v := request.AuditFlowConfig.NoApprover
if !(v == models.NoApproverPass || v == models.NoApproverToAdmin) {
... ... @@ -66,47 +57,18 @@ func (this *TemplateController) TemplateAdd() {
msg = protocol.BadRequestParam("10069")
return
}
var count int
for i := range request.AuditFlowConfig.ProcessConfig {
config := request.AuditFlowConfig.ProcessConfig[i]
if !(config.ApproveType == models.AuditByDepartmentor || config.ApproveType == models.AuditByUser || config.ApproveType == models.AuditByRole) {
msg = protocol.BadRequestParam("10171")
return
}
if !(config.AcitonType == models.ActionTypeOr || config.AcitonType == models.ActionTypeAnd) {
msg = protocol.BadRequestParam("10172")
return
}
if config.ApproveType == models.AuditByUser {
if len(config.ToUser) == 0 {
msg = protocol.BadRequestParam("10170")
return
}
if len(config.ToUser) > 10 {
msg = protocol.BadRequestParam("10174")
return
}
}
if config.ApproveType == models.AuditByRole {
if len(config.ToRole) == 0 {
msg = protocol.BadRequestParam("10173")
return
}
if len(config.ToRole) > 1 {
msg = protocol.BadRequestParam("10175")
return
}
}
if config.ProcessType == models.FlowTypeNormal {
count++
if count > 1 {
msg = protocol.BadRequestParam("10176")
return
}
}
}
}
{
if msg = audit.ValidFormList(request.Template.InputList); msg.Errno != 0 {
log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg)
return
}
if msg = audit.ValidAuditFlowConfig(request.AuditFlowConfig); msg.Errno != 0 {
log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg)
return
}
}
rsp, err := audit.TemplateAdd(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
return
... ... @@ -145,6 +107,17 @@ func (this *TemplateController) TemplateUpdate() {
msg = protocol.BadRequestParam("10272")
return
}
{
if msg = audit.ValidFormList(request.Template.InputList); msg.Errno != 0 {
log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg)
return
}
if msg = audit.ValidAuditFlowConfig(request.AuditFlowConfig); msg.Errno != 0 {
log.Error("valid fail ,code:%v msg:%v", msg.OriginErrno, msg.Errmsg)
return
}
}
rsp, err := audit.TemplateUpdate(uid, companyId, request)
msg = protocol.NewReturnResponse(rsp, err)
return
... ...
... ... @@ -122,3 +122,12 @@ func GetAuditTemplateByName(companyId int64, name string, chanceTypeId int) (v *
}
return
}
func GetAuditTemplateSort(companyId int64, chanceTypeId int) (v *ChanceType, err error) {
o := orm.NewOrm()
sql := "select max(sort_num) sort_num from audit_template where company_id=? and chance_type_id=?"
if err = o.Raw(sql, companyId, chanceTypeId).QueryRow(&v); err == nil {
return
}
return
}
... ...
... ... @@ -110,3 +110,13 @@ func GetChanceTypeByName(companyId int64, name string) (v *ChanceType, err error
}
return
}
//获取一级分类最大序号
func GetChanceTypeMaxSort(companyId int64) (v *ChanceType, err error) {
o := orm.NewOrm()
sql := "select max(sort_num) sort_num from chance_type where company_id=?"
if err = o.Raw(sql, companyId).QueryRow(&v); err == nil {
return
}
return
}
... ...
... ... @@ -35,14 +35,18 @@ type ResponseMessage struct {
Errno int `json:"code"`
Errmsg string `json:"msg"`
Data interface{} `json:"data"`
OriginErrno string `json:"-"`
}
func NewMessage(code string) *ResponseMessage {
ecode := SearchErr(code)
rsp := &ResponseMessage{
Errno: transformCode(ecode.Errno),
Errmsg: ecode.Errmsg,
Data: NullData,
Errno: transformCode(ecode.Errno),
Errmsg: ecode.Errmsg,
Data: NullData,
OriginErrno: code,
}
return rsp
}
... ...
... ... @@ -87,6 +87,9 @@ var errmessge ErrorMap = map[string]string{
"10281": "请您选择的审批人员",
"10282": "请您选择的审批角色",
"10283": "特殊审批流程被审批人不可重复",
"10284": "表单字段已经重复",
"10285": "未设置基础内容",
"10286": "未设置特殊审批人",
"10170": "请选择指定成员",
"10171": "请选择审批人类别",
... ...
... ... @@ -56,6 +56,11 @@ func TemplateAdd(uid, companyId int64, request *protocol.TemplateAddRequest) (rs
CreateAt: time.Now(),
UpdateAt: time.Now(),
}
if t, e := models.GetAuditTemplateSort(companyId, request.Template.ChanceTypeId); e == nil {
template.SortNum = t.SortNum + 1
} else {
template.SortNum = 1
}
if templateId, err = orm.Insert(template); err != nil {
log.Error(err.Error())
orm.Rollback()
... ... @@ -515,10 +520,18 @@ func TemplateDelete(uid, companyId int64, request *protocol.TemplateDeleteReques
return
}
orm := orm2.NewOrm()
orm.Begin()
if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFormBy, request.TemplateId, companyId); err != nil {
log.Error(err.Error())
orm.Rollback()
return
}
if err = utils.ExecuteSQLWithOrmer(orm, models.DeleteAuditFlowConfigSql, request.TemplateId); err != nil {
log.Error(err.Error())
orm.Rollback()
return
}
orm.Commit()
rsp = &protocol.TemplateDeleteResponse{}
return
}
... ... @@ -605,6 +618,11 @@ func TemplateOperateCategory(uid, companyId int64, request *protocol.TemplateOpe
err = protocol.NewErrWithMessage("10271")
return
}
if c, e := models.GetChanceTypeMaxSort(companyId); e == nil {
chanceType.SortNum = c.SortNum + 1
} else {
chanceType.SortNum = 1
}
if _, err = models.AddChanceType(chanceType); err != nil {
log.Error(err.Error())
}
... ... @@ -687,7 +705,7 @@ func CategoryEditSort(uid, companyId int64, request *protocol.CategoryEditSortRe
func ValidAuditFlowConfig(flowConfig protocol.AuditFlowConfig) (msg *protocol.ResponseMessage) {
var (
count int
specailUser map[int]int
specailUser map[int]int = make(map[int]int)
)
msg = protocol.NewMessage("0")
for i := range flowConfig.ProcessConfig {
... ... @@ -729,18 +747,16 @@ func ValidAuditFlowConfig(flowConfig protocol.AuditFlowConfig) (msg *protocol.Re
}
if config.ProcessType == models.FlowTypeSpecail {
if len(config.FromSpecialUser) == 0 { //特殊人为空
msg = protocol.BadRequestParam("10281")
msg = protocol.BadRequestParam("10286")
return
}
msg = ValidProcessConfig(&config)
if msg.Errno != 0 {
return
}
for i := range config.ToUser {
u := config.ToUser[i]
for i := range config.FromSpecialUser {
u := config.FromSpecialUser[i]
if _, ok := specailUser[u.Id]; ok {
msg = protocol.BadRequestParam("10283")
return
} else {
specailUser[u.Id] = u.Id
}
}
}
... ... @@ -769,3 +785,47 @@ func ValidProcessConfig(config *protocol.ProcessConfig) (msg *protocol.ResponseM
}
return
}
//校验表单
//名称不能超过20字
//表单项最低10个字段
//表单项不能重复
//基础表单项不能为空
func ValidFormList(inputs []*protocol.InputElement) (msg *protocol.ResponseMessage) {
msg = &protocol.ResponseMessage{}
var mapCheckRe map[string]string = make(map[string]string)
var countBasic, countExtral int
var countBasicRequire int
for i := range inputs {
input := inputs[i]
if len([]rune(input.Label)) > 20 {
msg = protocol.BadRequestParam("10273")
return
}
key := fmt.Sprintf("%v-%v", input.SectionType, input.Label)
if _, ok := mapCheckRe[key]; ok {
msg = protocol.BadRequestParam("10284")
return
} else {
mapCheckRe[key] = key
}
if input.SectionType == 1 {
countBasic++
}
if input.SectionType == 2 {
countExtral++
}
if input.SectionType == 1 && input.Required == 1 {
countBasicRequire++
}
}
if countBasic == 0 {
msg = protocol.BadRequestParam("10285")
return
}
if countBasic >= 10 || countExtral >= 10 {
msg = protocol.BadRequestParam("10274")
return
}
return
}
... ...
package audit
import (
"oppmg/models"
"oppmg/protocol"
"testing"
)
func Test_ValidFormList(t *testing.T) {
input := []*protocol.InputElement{
//{
// Label:"dsaghoida",
// SectionType:1,
//},
//{
// Label:"dsaghoida2",
// SectionType:1,
//},
{
Label: "dsaghoid",
SectionType: 2,
}, {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},
}
msg := ValidFormList(input)
if msg.Errno != 0 {
t.Log(msg.Errno, msg.Errmsg)
}
}
func Test_ValidAuditFlowConfig(t *testing.T) {
input := protocol.AuditFlowConfig{
NoApprover: 0,
ProcessConfig: []protocol.ProcessConfig{
{
ApproveType: models.AuditByRole,
ProcessType: models.FlowTypeSpecail,
AcitonType: models.ActionTypeAnd,
GroupId: 1,
FromSpecialUser: []protocol.VisibleObject{{Id: 1, Name: "1"}, {Id: 1, Name: "1"}},
ToUser: []protocol.VisibleObject{{Id: 1, Name: "1"}},
ToRole: []protocol.VisibleObject{{Id: 1, Name: "1"}},
},
},
}
msg := ValidAuditFlowConfig(input)
if msg.Errno != 0 {
t.Log(msg.OriginErrno, msg.Errmsg)
}
}
... ...