作者 yangfu

我审核的机会

... ... @@ -32,8 +32,10 @@
|机会更新| | | |
|机会删除| | |/v1/chance/delete|
|我的机会-我的审核| | | |
|机会审核(评分/修改公开状态)| | | |
|计算发现分| | | |
|机会审核| | | /v1/chance/approve|
|机会修改评分| | |/v1/chance/changeScore|
|机会修改公开状态| | |/v1/chance/changePublish|
|计算发现分| | |/v1/chance/calculateScore|
|用户机会权限| | | |
|机会池| | | |
|消息-点赞| | |v1/message/msgInteractive|
... ...
... ... @@ -54,9 +54,12 @@ func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.R
var err error
valid := validation.Validation{}
result, err = valid.Valid(obj)
//if err != nil {
// log.Error(err)
// msg = protocol.BadRequestParam(2)
// return
//}
if err != nil {
msg = protocol.BadRequestParam(1)
return
}
if !result {
for _, err := range valid.Errors {
... ...
... ... @@ -4,7 +4,6 @@ import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/controllers"
"opp/internal/utils"
"opp/protocol"
"opp/services/chance"
)
... ... @@ -346,7 +345,7 @@ func (this *ChanceController) ChanceApprove() {
var request *protocol.ChanceApproveRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
msg = protocol.BadRequestParam(2)
return
}
if b, m := this.Valid(request); !b {
... ... @@ -354,15 +353,8 @@ func (this *ChanceController) ChanceApprove() {
return
}
if request.ReviewStatus == protocol.ReviewStatusPass {
if utils.IsNil(request.ApproveData) {
msg = protocol.BadRequestParam(5204)
return
}
if utils.IsNil(request.ApproveData.PublicData) {
msg = protocol.BadRequestParam(5204)
return
}
if utils.IsNil(request.ApproveData.PublicData) {
status := request.ApproveData.PublicData.PublishStatus
if !(status == protocol.NoPublic || status == protocol.PublicToDepartment || status == protocol.PublicToCompany) {
msg = protocol.BadRequestParam(5204)
return
}
... ... @@ -370,3 +362,87 @@ func (this *ChanceController) ChanceApprove() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceApprove(header, request))
}
//ChanceChangePublish 修改公开状态
//@router /changePublish [post]
func (this *ChanceController) ChanceChangePublish() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceChangePublishRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceChangePublish(header, request))
}
//ChanceChangeScore 修改评分
//@router /changeScore [post]
func (this *ChanceController) ChanceChangeScore() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceChangeScoreRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceChangeScore(header, request))
}
//ChanceCalculateScore 计算发现分
//@router /calculateScore [post]
func (this *ChanceController) ChanceCalculateScore() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceCalculateScoreRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.ChanceCalculateScore(header, request))
}
//MyApproveChance 我审核的机会
//@router /myApproveChance [post]
func (this *ChanceController) MyApproveChance() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.MyApproveChanceRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.MyApproveChance(header, request))
}
... ...
... ... @@ -15,10 +15,10 @@ type AuditFlowProcess struct {
Level int `orm:"column(level)" description:"审批步骤"`
IsActive int8 `orm:"column(is_active)" description:"是否激活"`
ApproveTime time.Time `orm:"column(approve_time);type(timestamp)" description:"审批时间"`
BasicSorce float64 `orm:"column(basic_sorce);null;digits(4);decimals(1)" description:"基础评分"`
ExtraSorce float64 `orm:"column(extra_sorce);null;digits(4);decimals(1)" description:"附加评分"`
ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
DiscoverySorce float64 `orm:"column(discovery_sorce);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
BasicScore float64 `orm:"column(basic_score);null;digits(4);decimals(1)" description:"基础评分"`
ExtraScore float64 `orm:"column(extra_score);null;digits(4);decimals(1)" description:"附加评分"`
ValueScore float64 `orm:"column(value_score);null;digits(4);decimals(1)" description:"价值评分"`
DiscoveryScore float64 `orm:"column(discovery_score);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
ReviewStatus int8 `orm:"column(review_status)" description:"审核状态 0:审核中 1:被退回 2:已通过 3.自动通过 "`
AuditFlowType int `orm:"column(audit_flow_type)" description:"审核流类型 1.部门长 2.指定成员 3.指定角色 4.特殊审核人"`
FlowType int `orm:"column(flow_type)" description:"审批类型 1:正常审核 2:特殊审核"`
... ...
... ... @@ -25,12 +25,12 @@ type Chance struct {
EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "`
UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"`
CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"`
BasicSorce float64 `orm:"column(basic_sorce);null;digits(4);decimals(1)" description:"基础评分"`
ExtraSorce float64 `orm:"column(extra_sorce);null;digits(4);decimals(1)" description:"附加评分"`
ValueSorce float64 `orm:"column(value_sorce);null;digits(4);decimals(1)" description:"价值评分"`
DiscoverySorce float64 `orm:"column(discovery_sorce);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
BasicScore float64 `orm:"column(basic_score);null;digits(4);decimals(1)" description:"基础评分"`
ExtraScore float64 `orm:"column(extra_score);null;digits(4);decimals(1)" description:"附加评分"`
ValueScore float64 `orm:"column(value_score);null;digits(4);decimals(1)" description:"价值评分"`
DiscoveryScore float64 `orm:"column(discovery_score);null;digits(4);decimals(1)" description:"发现得分(发现得分=基础评分*系数 + 附加评分*系数 + 价值评分*系数)"`
PublishStatus int `orm:"column(publish_status)" description:"公开状态 0未公开、1部门公开、2公司公开"`
PublishData string `orm:"column(publish_data)" description:"公开数据 冗余"`
ApproveData string `orm:"column(approve_data)" description:"审核数据 冗余"`
AuditLevel int `orm:"column(audit_level)" description:"当前审批步骤"`
}
... ... @@ -61,6 +61,15 @@ func GetChanceById(id int64) (v *Chance, err error) {
return nil, err
}
func GetChanceByIdAndEnable(id int64) (v *Chance, err error) {
o := orm.NewOrm()
v = &Chance{Id: id, EnableStatus: 1}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChance updates Chance by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceById(m *Chance) (err error) {
... ... @@ -115,3 +124,26 @@ order by create_at desc
}
return
}
func GetChanceMyApproveChance(uid, cid int64, reviewStatus []int8, lastId int64, pageSize int, v interface{}) (total int, err error) {
sql := `select a.*,b.images,b.speechs,b.videos from (
select a.*,b.user_id,b.source_content,b.enable_status from (
select id,approve_time,approve_data,uid,chance_id
from audit_flow_process where uid=? and enable_status =1 and review_status in (?) and (?=0 or id>?)
)a left outer join chance b on a.chance_id = b.id
)a left outer join chance_data b on a.chance_id =b.chance_id
order by a.approve_time desc
LIMIT ?`
sqlCount := `select count(0)
from audit_flow_process where uid=? and enable_status =1 and review_status in (?) `
if err = utils.ExecuteQueryOne(&total, sqlCount, uid, utils.JoinInt8s(reviewStatus, ",")); err != nil {
return
}
if v != nil {
if err = utils.ExecuteQueryAll(v, sql, uid, utils.JoinInt8s(reviewStatus, ","), lastId, lastId, pageSize); err != nil {
return
}
}
return
}
... ...
package models
import (
"fmt"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceDepartment struct {
Id int64 `orm:"column(id);pk" description:"唯一编号"`
ChanceId int64 `orm:"column(chance_id)" description:"表chance.id 机会编号"`
DepartmentId int64 `orm:"column(department_id)" description:"表department.id 部门编号"`
EnableStatus int8 `orm:"column(enable_status)" description:"有效状态 0:无效 1:有效 "`
CreateAt time.Time `orm:"column(create_at);type(timestamp);auto_now" description:"创建时间"`
DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"`
}
var (
SqlDeleteChanceDepartment = "delete from chance_department where chance_id =? and enable_status=1"
)
func (t *ChanceDepartment) TableName() string {
return "chance_department"
}
func init() {
orm.RegisterModel(new(ChanceDepartment))
}
// AddChanceDepartment insert a new ChanceDepartment into database and returns
// last inserted Id on success.
func AddChanceDepartment(m *ChanceDepartment) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceDepartmentById retrieves ChanceDepartment by Id. Returns error if
// Id doesn't exist
func GetChanceDepartmentById(id int64) (v *ChanceDepartment, err error) {
o := orm.NewOrm()
v = &ChanceDepartment{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceDepartment updates ChanceDepartment by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceDepartmentById(m *ChanceDepartment) (err error) {
o := orm.NewOrm()
v := ChanceDepartment{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceDepartment deletes ChanceDepartment by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceDepartment(id int64) (err error) {
o := orm.NewOrm()
v := ChanceDepartment{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceDepartment{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
... ...
... ... @@ -43,9 +43,9 @@ const (
//公开状态
const (
NoPublic = 0 //未公开
PublicToDepartment = 1 //部门公开
PublicToCompany = 2 //公司公开
NoPublic = -1 //未公开
PublicToDepartment = 1 //部门公开
PublicToCompany = 2 //公司公开
)
/*Favorite */
... ... @@ -194,6 +194,31 @@ type MySubmitChanceResponse struct {
Total int `json:"total"`
}
/*MyApproveChance 我审核的机会*/
type MyApproveChanceRequest struct {
LastId int64 `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
ReviewStatus int8 `json:"reviewStatus"` //审核状态
}
type MyApproveChanceResponse struct {
List []CommonListItem `json:"list"`
Total int `json:"total"`
}
//机会列表 通用项
type CommonListItem struct {
Chance ChanceItem `json:"chance,omitempty"` //机会详情
ChanceData ChanceData `json:"chanceData,omitempty"` //机会数据(是否收藏/点赞 浏览数 点赞总数 评论数)
Approve Approve `json:"approve,omitempty"` //审核人 审核信息(时间)
ApproveData ApproveData `json:"ApproveData"` //审核数据(公开状态 评分)
Message interface{} `json:"message,omitempty"`
Comment interface{} `json:"comment,omitempty"`
ChanceStatus int `json:"chanceStatus,omitempty"` //1.删除 2.关闭
}
type ChanceData struct {
}
//我的机会列表
type ChanceItemOrm struct {
Id int64 `orm:"column(id)"`
... ... @@ -214,13 +239,29 @@ type ChanceItem struct {
Videos []Video `json:"videos"`
}
//我的审核机会列表
type ChanceApproveItemOrm struct {
ChanceUserId int64 `orm:"column(chance_user_id)"`
SourceContent string `orm:"column(source_content)"`
ChanceEnableStatus string `orm:"column(enable_status)"`
Images string `orm:"column(images)"`
Voices string `orm:"column(speechs)"`
Videos string `orm:"column(videos)"`
Id int64 `orm:"column(id)"` //审核id
ApproveTime time.Time `orm:"column(approve_time)"`
ApproveData string `orm:"column(approve_data)"`
ApproveUserId int64 `orm:"column(uid)"`
ChanceId int64 `orm:"column(chance_id)"` // 机会id
}
/*ChanceDetail 机会详情*/
type ChanceDetailRequest struct {
Id int64 `json:"id"` //机会编号
}
type ChanceDetailResponse struct {
ChanceDetail ChanceItem `json:"chanceDetail"`
PublicData *PublicData `json:"publicData"`
ApproveData *ApproveData `json:"publicData"`
ApproveProcess []*ProcessItem `json:"approveProcess"`
ApproveAccess *ApproveAccess `json:"approveAccess"` //
}
... ... @@ -231,3 +272,27 @@ type ChanceDeleteRequest struct {
}
type ChanceDeleteResponse struct {
}
/*ChanceChangePublish 修改公开状态*/
type ChanceChangePublishRequest struct {
ChanceId int64 `json:"chanceId"` //机会编号
PublicData PublicData `json:"publicData"` // 公开数据
}
type ChanceChangePublishResponse struct {
}
/*ChanceChangeScore 修改评分*/
type ChanceChangeScoreRequest struct {
ChanceId int64 `json:"chanceId"` //机会编号
Score Score `json:"score"`
}
type ChanceChangeScoreResponse struct {
}
/*ChanceCalculateScore 计算发现分*/
type ChanceCalculateScoreRequest struct {
Score Score `json:"score"`
}
type ChanceCalculateScoreResponse struct {
DiscoveryScore float64 `json:"discoveryScore"` //发现分
}
... ...
... ... @@ -66,6 +66,12 @@ type Role struct {
Name string `json:"name"`
}
type Approve struct {
Provider BaseUserInfo `json:"provider"`
ProcessId int64 `json:"processId"`
ApproveTime int64 `json:"approveTime"`
}
//审核数据 审核通过
type ApproveData struct {
PublicData PublicData `json:"publicData"` // 公开数据
... ... @@ -80,17 +86,17 @@ type PublicData struct {
//可见对象
type VisibleObject struct {
Id string `json:"id"`
Id int64 `json:"id"`
Name string `json:"name,omitempty"`
Type int `json:"type"` //1:部门 2:指定人员
}
//评分
type Score struct {
BasicScore float32 `json:"basicScore"` //基础评分
ExtraScore float32 `json:"extraScore"` //额外分
ValueScore float32 `json:"valueScore"` //价值分
DiscoveryScore float32 `json:"discoveryScore"` //发现分
BasicScore float64 `json:"basicScore"` //基础评分
ExtraScore float64 `json:"extraScore"` //额外分
ValueScore float64 `json:"valueScore"` //价值分
DiscoveryScore float64 `json:"discoveryScore"` //发现分
}
//审核操作权限
... ...
... ... @@ -40,6 +40,7 @@ var errmessge ErrorMap = map[int]string{
5202: "该机会已被审批",
5203: "审批服务器操作失败",
5204: "评分或者公开状态不能为空",
5205: "机会未审核通过,不能修改评分或者公开状态",
//模板相关
5301: "机会模板不存在",
... ...
... ... @@ -65,6 +65,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceCalculateScore",
Router: `/calculateScore`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceDetail",
Router: `/chanceDetail`,
AllowHTTPMethods: []string{"post"},
... ... @@ -81,6 +89,22 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceChangePublish",
Router: `/changePublish`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceChangeScore",
Router: `/changeScore`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "CommentDetailsMulti",
Router: `/commentDetailsMulti`,
AllowHTTPMethods: []string{"post"},
... ... @@ -137,6 +161,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "MyApproveChance",
Router: `/myApproveChance`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "MySubmitChance",
Router: `/mySubmitChance`,
AllowHTTPMethods: []string{"post"},
... ...
package chance
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/httplib"
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"io/ioutil"
"net/http"
... ... @@ -14,8 +16,6 @@ import (
"opp/protocol"
"opp/services/agg"
"time"
"encoding/json"
)
var (
... ... @@ -272,8 +272,8 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
suplusApprove SuplusApprove
approveType int
approveItemResponse ApproveItemResponse
mapProcess map[string]interface{}
mapChance map[string]interface{}
mapProcess = make(map[string]interface{})
mapChance = make(map[string]interface{})
)
rsp = &protocol.ChanceApproveResponse{}
//TODO:测试注入
... ... @@ -301,35 +301,29 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
err = protocol.NewErrWithMessage(5202)
return
}
log.Info(fmt.Sprintf("用户:%v 提交审核 机会编号:%v 审批流编号:%v 审批状态:%v", header.UserId, chance.Id, process.Id, request.ReviewStatus))
if approveItemResponse, err = suplusApprove.ApproveItem(header, approveType, chance.Id, process.Id); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(5203)
return
}
{
mapProcess["ReviewStatus"] = int8(request.ReviewStatus)
mapProcess["ApproveTime"] = time.Now()
if request.ReviewStatus == protocol.ReviewStatusPass {
mapProcess["BasicSorce"] = request.ApproveData.Score.BasicScore
mapProcess["ExtraSorce"] = request.ApproveData.Score.ExtraScore
mapProcess["ValueSorce"] = request.ApproveData.Score.ValueScore
mapProcess["DiscoverySorce"] = request.ApproveData.Score.DiscoveryScore
mapProcess["BasicScore"] = request.ApproveData.Score.BasicScore
mapProcess["ExtraScore"] = request.ApproveData.Score.ExtraScore
mapProcess["ValueScore"] = request.ApproveData.Score.ValueScore
mapProcess["DiscoveryScore"] = request.ApproveData.Score.DiscoveryScore
mapProcess["ApproveData"] = common.AssertJson(request.ApproveData)
mapProcess["EnableStatus"] = int8(1)
mapChance["BasicSorce"] = request.ApproveData.Score.BasicScore
mapChance["ExtraSorce"] = request.ApproveData.Score.ExtraScore
mapChance["ValueSorce"] = request.ApproveData.Score.ValueScore
mapChance["DiscoverySorce"] = request.ApproveData.Score.DiscoveryScore
mapChance["BasicScore"] = request.ApproveData.Score.BasicScore
mapChance["ExtraScore"] = request.ApproveData.Score.ExtraScore
mapChance["ValueScore"] = request.ApproveData.Score.ValueScore
mapChance["DiscoveryScore"] = request.ApproveData.Score.DiscoveryScore
mapChance["ApproveData"] = common.AssertJson(request.ApproveData)
mapChance["PublishStatus"] = request.ApproveData.PublicData.PublishStatus
}
}
orm := orm.NewOrm()
orm.Begin()
if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil {
log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err)
orm.Rollback()
log.Info(fmt.Sprintf("用户:%v 提交审核 机会编号:%v 审批流编号:%v 审批状态:%v", header.UserId, chance.Id, process.Id, request.ReviewStatus))
if approveItemResponse, err = suplusApprove.ApproveItem(header, approveType, chance.Id, process.Id); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(5203)
return
}
log.Info(fmt.Sprintf("用户%v 更新机会审核状态 process_id:%v 状态:%v", header.UserId, process.Id, request.ReviewStatus))
... ... @@ -382,12 +376,41 @@ func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceAppro
}
}
}
orm := orm.NewOrm()
orm.Begin()
if err = utils.UpdateTableByMapWithOrmer(orm, process, mapProcess); err != nil {
log.Error("更新机会审核流程 状态失败 process_id:", process.Id, err)
orm.Rollback()
return
}
if err = utils.UpdateTableByMapWithOrmer(orm, chance, mapChance); err != nil {
orm.Rollback()
log.Error("更新机会审核状态失败 chance_id:", chance.Id, err)
return
}
if request.ApproveData.PublicData.PublishStatus == protocol.PublicToDepartment {
if err = utils.ExecuteSQLWithOrmer(orm, models.SqlDeleteChanceDepartment, chance.Id); err != nil {
log.Error(err)
orm.Rollback()
return
}
vObjs := request.ApproveData.PublicData.VisibleObjects
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()
return
}
... ... @@ -484,10 +507,16 @@ func ChanceApproveProcess(header *protocol.RequestHeader, chance *models.Chance)
checkApprovePermission(p)
//机会已经审核通过的直接添加到审核人列表
if chance.ReviewStatus == protocol.ReviewStatusPass {
if e := json.Unmarshal([]byte(p.ApproveData), &item.ApproveData); e != nil {
log.Error(e)
}
rsp.ApproveProcess = append(rsp.ApproveProcess, item)
continue
}
if p.ReviewStatus == protocol.ReviewStatusPass {
if e := json.Unmarshal([]byte(p.ApproveData), &item.ApproveData); e != nil {
log.Error(e)
}
rsp.ApproveProcess = append(rsp.ApproveProcess, item)
continue
}
... ...
... ... @@ -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
}
... ...