...
|
...
|
@@ -264,30 +264,29 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
ReviewStatus: protocol.ReviewStatusAuditging,
|
|
|
DepartmentId: request.RelatedDepartment,
|
|
|
}
|
|
|
logAndRollBack := func(err error) {
|
|
|
if _, err = orm.Insert(chance); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if _, err = orm.Insert(chance); err != nil {
|
|
|
logAndRollBack(err)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//生成提交记录
|
|
|
if _, err = orm.Insert(GenAuditFlowProcess_Submit(header, chance.Id, template.Id)); err != nil {
|
|
|
logAndRollBack(err)
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
//4.查询审核配置
|
|
|
//5.生成审核流
|
|
|
if auditFlows, err = GenAuditFlowProcess(header, chance.Id, template.Id, auditConfig); err != nil {
|
|
|
logAndRollBack(err)
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
for i := 0; i < len(auditFlows); i++ {
|
|
|
if _, err = orm.Insert(auditFlows[i]); err != nil {
|
|
|
logAndRollBack(err)
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -304,7 +303,8 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
message := m.MessageData[i]
|
|
|
if err = agg.SendApproveMsg(message.ReceiverInfo.ReceiverUid, message.ReceiverInfo.ReceiverName,
|
|
|
header.CompanyId, chance.Id, chance.ChanceTypeId, protocol.ReviewStatusAuditging); err != nil {
|
|
|
logAndRollBack(err)
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -323,7 +323,8 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
UpdateAt: time.Now(),
|
|
|
}
|
|
|
if _, err = orm.Insert(data); err != nil {
|
|
|
logAndRollBack(err)
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -333,6 +334,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
return
|
|
|
}
|
|
|
|
|
|
//机会编辑
|
|
|
func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
|
|
|
var (
|
|
|
template *models.AuditTemplate
|
...
|
...
|
@@ -412,6 +414,112 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceSubmit |
|
|
return
|
|
|
}
|
|
|
|
|
|
//修改公开状态
|
|
|
func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.ChanceChangePublishRequest) (rsp *protocol.ChanceChangePublishResponse, err error) {
|
|
|
var (
|
|
|
chance *models.Chance
|
|
|
mapChance = make(map[string]interface{})
|
|
|
approveData protocol.ApproveData
|
|
|
)
|
|
|
if chance, err = models.GetChanceByIdAndEnable(request.ChanceId); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5101) //不存在
|
|
|
return
|
|
|
}
|
|
|
if chance.ReviewStatus != protocol.ReviewStatusPass {
|
|
|
err = protocol.NewErrWithMessage(5205)
|
|
|
return
|
|
|
}
|
|
|
//TODO:角色检查权限
|
|
|
if e := json.Unmarshal([]byte(chance.ApproveData), &approveData); e == nil {
|
|
|
approveData.PublicData = request.PublicData
|
|
|
}
|
|
|
{
|
|
|
mapChance["ApproveData"] = common.AssertJson(approveData)
|
|
|
mapChance["PublishStatus"] = request.PublicData.PublishStatus
|
|
|
}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteChanceDepartment, chance.Id); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
if err = utils.UpdateTableByMapWithOrmer(orm, chance, mapChance); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
vObjs := request.PublicData.VisibleObjects
|
|
|
if request.PublicData.PublishStatus == protocol.PublicToDepartment {
|
|
|
if len(vObjs) > 0 {
|
|
|
for i := range vObjs {
|
|
|
if _, err = orm.Insert(&models.ChanceDepartment{
|
|
|
Id: idgen.Next(),
|
|
|
ChanceId: chance.Id,
|
|
|
DepartmentId: vObjs[i].Id,
|
|
|
EnableStatus: 1,
|
|
|
CreateAt: time.Now(),
|
|
|
}); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
orm.Commit()
|
|
|
//TODO:添加log
|
|
|
rsp = &protocol.ChanceChangePublishResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//修改评分
|
|
|
func ChanceChangeScore(header *protocol.RequestHeader, request *protocol.ChanceChangeScoreRequest) (rsp *protocol.ChanceChangeScoreResponse, err error) {
|
|
|
var (
|
|
|
chance *models.Chance
|
|
|
mapChance = make(map[string]interface{})
|
|
|
approveData protocol.ApproveData
|
|
|
)
|
|
|
if chance, err = models.GetChanceByIdAndEnable(request.ChanceId); err != nil {
|
|
|
err = protocol.NewErrWithMessage(5101) //不存在
|
|
|
return
|
|
|
}
|
|
|
if chance.ReviewStatus != protocol.ReviewStatusPass {
|
|
|
err = protocol.NewErrWithMessage(5205)
|
|
|
return
|
|
|
}
|
|
|
//TODO:角色检查权限
|
|
|
if e := json.Unmarshal([]byte(chance.ApproveData), &approveData); e == nil {
|
|
|
approveData.Score = request.Score
|
|
|
}
|
|
|
{
|
|
|
mapChance["ApproveData"] = common.AssertJson(approveData)
|
|
|
mapChance["BasicScore"] = request.Score.BasicScore
|
|
|
mapChance["ExtraScore"] = request.Score.ExtraScore
|
|
|
mapChance["ValueScore"] = request.Score.ValueScore
|
|
|
mapChance["DiscoveryScore"] = request.Score.DiscoveryScore
|
|
|
}
|
|
|
orm := orm.NewOrm()
|
|
|
orm.Begin()
|
|
|
if err = utils.UpdateTableByMapWithOrmer(orm, chance, mapChance); err != nil {
|
|
|
log.Error(err)
|
|
|
orm.Rollback()
|
|
|
return
|
|
|
}
|
|
|
orm.Commit()
|
|
|
rsp = &protocol.ChanceChangeScoreResponse{}
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//计算发现分
|
|
|
func ChanceCalculateScore(header *protocol.RequestHeader, request *protocol.ChanceCalculateScoreRequest) (rsp *protocol.ChanceCalculateScoreResponse, err error) {
|
|
|
var ()
|
|
|
//TODO:取配置数据
|
|
|
rsp = &protocol.ChanceCalculateScoreResponse{}
|
|
|
rsp.DiscoveryScore = request.Score.BasicScore*1.0 + request.Score.ExtraScore*1.0 + request.Score.ValueScore*1.0
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//生成审批流-提交记录
|
|
|
func GenAuditFlowProcess_Submit(header *protocol.RequestHeader, chanceId int64, templateId int64) (v *models.AuditFlowProcess) {
|
|
|
v = &models.AuditFlowProcess{
|
...
|
...
|
@@ -683,6 +791,49 @@ func MySubmitChance(header *protocol.RequestHeader, request *protocol.MySubmitCh |
|
|
return
|
|
|
}
|
|
|
|
|
|
//我审核的机会
|
|
|
func MyApproveChance(header *protocol.RequestHeader, request *protocol.MyApproveChanceRequest) (rsp *protocol.MyApproveChanceResponse, err error) {
|
|
|
var (
|
|
|
myChances []protocol.ChanceApproveItemOrm
|
|
|
total int
|
|
|
provider *protocol.BaseUserInfo
|
|
|
)
|
|
|
rsp = &protocol.MyApproveChanceResponse{}
|
|
|
if total, err = models.GetChanceMyChance(header.UserId, header.CompanyId, []int8{request.ReviewStatus}, request.LastId, request.PageSize, &myChances); err != nil {
|
|
|
if err == orm.ErrNoRows {
|
|
|
err = nil
|
|
|
return
|
|
|
}
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
if provider, err = agg.GetUserBaseInfo(header.UserId, header.CompanyId); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.MyApproveChanceResponse{Total: total}
|
|
|
for i := 0; i < len(myChances); i++ {
|
|
|
chance := myChances[i]
|
|
|
commItem := protocol.CommonListItem{}
|
|
|
item := protocol.ChanceItem{
|
|
|
Id: chance.Id,
|
|
|
Provider: provider,
|
|
|
//CreateTime: chance.CreateTime.Unix() * 1000,
|
|
|
}
|
|
|
jsonUnmarshal(chance.SourceContent, &item.FormList)
|
|
|
jsonUnmarshal(chance.Images, &item.Pictures)
|
|
|
jsonUnmarshal(chance.Voices, &item.Speechs)
|
|
|
jsonUnmarshal(chance.Videos, &item.Videos)
|
|
|
|
|
|
{
|
|
|
commItem.Chance = item
|
|
|
}
|
|
|
rsp.List = append(rsp.List, commItem)
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func jsonUnmarshal(jsonData string, v interface{}) {
|
|
|
if len(jsonData) == 0 {
|
|
|
return
|
...
|
...
|
@@ -730,7 +881,7 @@ func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetail |
|
|
jsonUnmarshal(chanceData.Speechs, &item.Speechs)
|
|
|
jsonUnmarshal(chanceData.Videos, &item.Videos)
|
|
|
}
|
|
|
jsonUnmarshal(chance.PublishData, &rsp.PublicData)
|
|
|
jsonUnmarshal(chance.ApproveData, &rsp.ApproveData)
|
|
|
rsp.ChanceDetail = item
|
|
|
if approveProcess, err = ChanceApproveProcess(header, chance); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -761,7 +912,7 @@ func ChanceDelete(header *protocol.RequestHeader, request *protocol.ChanceDelete |
|
|
return
|
|
|
}
|
|
|
//被人审核过 公开状态数据不为空
|
|
|
if chance.ReviewStatus == protocol.ReviewStatusAuditging && len(chance.PublishData) != 0 {
|
|
|
if chance.ReviewStatus == protocol.ReviewStatusAuditging && len(chance.ApproveData) != 0 {
|
|
|
err = protocol.NewErrWithMessage(5202)
|
|
|
return
|
|
|
}
|
...
|
...
|
|