作者 yangfu

自查修改

... ... @@ -110,7 +110,7 @@ func GetAuditTemplateExample(id int64) (v string, videos string, err error) {
//获取审核模板列表
func GetAuditTemplate(companyId int64, chanceTypeId, templateId int) (v *AuditTemplate, err error) {
o := orm.NewOrm()
sql := "select * from audit_template where id=? and company_id=? and chance_type_id=? and enable_status=1"
sql := "select id,company_id,chance_type_id,`name`,doc,icon,code,sort_num,visible_type,visible_object,LEFT(example,5) example,videos from audit_template where id=? and company_id=? and chance_type_id=? and enable_status=1"
if err = o.Raw(sql, templateId, companyId, chanceTypeId).QueryRow(&v); err == nil {
return
}
... ...
... ... @@ -18,6 +18,7 @@ type ChanceSelfCheck struct {
Reason string `orm:"column(reason);size(200);null" description:"理由"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"`
Enable int8 `orm:"column(enable);size(200);null" description:"是否有效【0:无效】【1:有效】"`
}
func (t *ChanceSelfCheck) TableName() string {
... ...
... ... @@ -313,7 +313,8 @@ func getQuestionTitle(groupIdx int, idx int, title string) string {
}
//自查问题回答批量入库
func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks) {
//@isDelete
func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks, isDeleteExisted bool) {
defer func() {
if p := recover(); p != nil {
log.Warn(p)
... ... @@ -323,7 +324,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int
count int
err error
Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
DeleteExistedRow = `update chance_self_check set enable=0 where chanceId=? and relateId=?`
DeleteExistedRow = `update chance_self_check set enable=0,update_at=Now() where relateId=? and enable=1`
)
if len(selfChecks) == 0 {
return
... ... @@ -335,32 +336,48 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int
o.Rollback()
return
}
if count > 0 {
if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedRow, relateId, chanceId); err != nil {
if isDeleteExisted {
if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedRow, chanceId); err != nil {
log.Error(err)
o.Rollback()
return
}
}
for i := range selfChecks {
check := selfChecks[i]
m := models.ChanceSelfCheck{
Id: idgen.Next(),
UserCompanyId: header.UserId,
ChanceId: chanceId,
RelateId: relateId,
CheckItem: check.CheckItem,
GroupId: check.GroupId,
Answer: check.Answer,
Reason: check.Reason,
CreateAt: time.Now(),
}
if _, err = o.Insert(m); err != nil {
log.Error(err)
o.Rollback()
if count == 0 {
insertFunc := func(check protocol.SelfCheck, r int64) (err error) {
m := &models.ChanceSelfCheck{
Id: idgen.Next(),
UserCompanyId: header.UserId,
ChanceId: chanceId,
RelateId: r,
CheckItem: check.CheckItem,
GroupId: check.GroupId,
Answer: check.Answer,
Reason: check.Reason,
CreateAt: time.Now(),
UpdateAt: time.Now(),
Enable: protocol.Valid,
}
//插入审核的自查内容
if _, err = o.Insert(m); err != nil {
log.Error(err)
o.Rollback()
return
}
return
}
for i := range selfChecks {
check := selfChecks[i]
if err = insertFunc(check, relateId); err != nil {
return
}
//审核通过更新之前机会的自查内容(重新插入一条机会的自查内容)
if isDeleteExisted {
if err = insertFunc(check, chanceId); err != nil {
return
}
}
}
}
o.Commit()
}
... ...
... ... @@ -456,6 +456,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
}
}
}
go agg.BulkInsertSelfChecks(header, process.Id, chance.Id, request.SelfChecks, request.ReviewStatus == protocol.ReviewStatusPass)
orm.Commit()
return
}
... ...
... ... @@ -486,6 +486,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
return
}
}
go agg.BulkInsertSelfChecks(header, chance.Id, chance.Id, request.SelfChecks, false)
orm.Commit()
rsp = &protocol.ChanceSubmitResponse{}
... ...