...
|
...
|
@@ -314,50 +314,38 @@ func getQuestionTitle(groupIdx int, idx int, title string) string { |
|
|
|
|
|
//自查问题回答批量入库
|
|
|
//@isDelete
|
|
|
func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks, isDeleteExisted bool) {
|
|
|
func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int64, selfChecks protocol.SelfChecks, isDeleteExisted bool, checkerType int) {
|
|
|
defer func() {
|
|
|
if p := recover(); p != nil {
|
|
|
log.Warn(p)
|
|
|
}
|
|
|
}()
|
|
|
var (
|
|
|
count int
|
|
|
err error
|
|
|
Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
|
|
|
DeleteExistedRow = `update chance_self_check set enable=0,update_at=Now() where relateId=? and enable=1`
|
|
|
count int
|
|
|
err error
|
|
|
Exists = `select count(0) from chance_self_check where chanceId=? and relateId=?`
|
|
|
DeleteExistedSubmitRow = `delete from chance_self_check where relateId=? and type=? and user_company_id=?` //删除提交人自查数据
|
|
|
)
|
|
|
if len(selfChecks) == 0 {
|
|
|
return
|
|
|
}
|
|
|
o := orm.NewOrm()
|
|
|
o.Begin()
|
|
|
if err = utils.ExecuteQueryOneWithOrmer(o, &count, Exists, relateId, chanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if isDeleteExisted {
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedRow, chanceId); err != nil {
|
|
|
if err = utils.ExecuteSQLWithOrmer(o, DeleteExistedSubmitRow, chanceId, checkerType, header.UserId); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
if err = utils.ExecuteQueryOneWithOrmer(o, &count, Exists, relateId, chanceId); err != nil {
|
|
|
log.Error(err)
|
|
|
o.Rollback()
|
|
|
return
|
|
|
}
|
|
|
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,
|
|
|
}
|
|
|
m := NewChanceSelfCheck(header, check, chanceId, r, checkerType)
|
|
|
//插入审核的自查内容
|
|
|
if _, err = o.Insert(m); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -372,7 +360,7 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
|
|
return
|
|
|
}
|
|
|
//审核通过更新之前机会的自查内容(重新插入一条机会的自查内容)
|
|
|
if isDeleteExisted {
|
|
|
if checkerType == protocol.TypeApprove && isDeleteExisted {
|
|
|
if err = insertFunc(check, chanceId); err != nil {
|
|
|
return
|
|
|
}
|
...
|
...
|
@@ -381,3 +369,20 @@ func BulkInsertSelfChecks(header *protocol.RequestHeader, relateId, chanceId int |
|
|
}
|
|
|
o.Commit()
|
|
|
}
|
|
|
|
|
|
func NewChanceSelfCheck(header *protocol.RequestHeader, check protocol.SelfCheck, chanceId, r int64, checkerType int) *models.ChanceSelfCheck {
|
|
|
return &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(),
|
|
|
CompanyId: header.CompanyId,
|
|
|
Type: checkerType,
|
|
|
}
|
|
|
} |
...
|
...
|
|