作者 yangfu

机会审核

appname = opportunity
httpport = 8080
runmode = "${RUN_MODE||local}"
runmode = "${RUN_MODE||dev}"
#没设置的话 this.Ctx.Input.RequestBody 没有值
copyrequestbody = true
... ... @@ -10,7 +10,7 @@ copyrequestbody = true
#开启应用内文档开关
EnableDocs = true
include "local.conf"
include "dev.conf"
include "dev-online.conf"
include "test.conf"
include "prod.conf"
... ...
[local]
[dev]
#数据库相关
mysql_user = "${MYSQL_USER||root}"
mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"
... ...
... ... @@ -316,36 +316,22 @@ func (this *ChanceController) ChanceDelete() {
}
//ChanceApprove 机会审核
//func(this *ChanceController)ChanceApprove(){
// var msg *protocol.ResponseMessage
// defer func() {
// this.Resp(msg)
// }()
// var request *protocol.ChanceApproveRequest
// 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.ChanceApprove(header,request))
//}
//
///*ChanceApprove */
//type ChanceApproveRequest struct {
// Xxx string`json:"xxx" valid:"Required"`
//}
//type ChanceApproveResponse struct {
//}
//
//func ChanceApprove(header *protocol.RequestHeader,request *protocol.ChanceApproveRequest)(rsp *protocol.ChanceApproveResponse,err error){
// var (
//
// )
// rsp =&protocol.ChanceApproveResponse{}
// return
//}
//@router /approve [post]
func (this *ChanceController) ChanceApprove() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceApproveRequest
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.ChanceApprove(header, request))
}
... ...
... ... @@ -82,3 +82,14 @@ func DeleteAuditFlowProcess(id int64) (err error) {
}
return
}
//审核流程编号 按用户编号
//获取审核流节点
func GetAuditFlowProcessBy(processId, uid int64) (v *AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_process where id=? and uid=? and enable_status=1"
if err = o.Raw(sql, processId, uid).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
package protocol
const (
ApproveTypePass = 2 //审核通过
ApproveTypeReject = 3 //审核驳回
//ApproveReturn =4 //审核撤回
)
type ApproveProcess struct {
//RelativeId int64 `json:"relativeId"`
Uid int64 `json:"uid"`
... ... @@ -9,3 +15,14 @@ type ApproveProcess struct {
Active int `json:"active"`
ApproveTime int64 `json:"approveTime"` //审核时间
}
/*ChanceApprove 机会审核*/
type ChanceApproveRequest struct {
Uid int64 `json:"uid"` //TODO:测试使用 注入审核人
ChanceId int64 `json:"chanceId"` //机会编号
ProcessId int64 `json:"processId"` //审批流程编号
ReviewStatus int `json:"reviewStatus"` //protocol.ReviewStatus
//Suggestion string `json:"suggestion"` //原因/建议
}
type ChanceApproveResponse struct {
}
... ...
... ... @@ -37,6 +37,8 @@ var errmessge ErrorMap = map[int]string{
//机会审批相关
5201: "该机会模板未配置审批人,请选择其他模板",
5202: "该机会已被其他人审批",
5203: "审批服务器操作失败",
}
const (
... ...
... ... @@ -57,6 +57,30 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceApprove",
Router: `/approve`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceDelete",
Router: `/chanceDelete`,
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"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "ChanceType",
Router: `/chanceType`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -100,19 +100,20 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
}
//审批操作
func (s SuplusApprove) ApproveItem(header *protocol.RequestHeader, approveType int, chanceId int64) (response ApproveItemResponse, err error) {
func (s SuplusApprove) ApproveItem(header *protocol.RequestHeader, approveType int, chanceId int64, processId int64) (response ApproveItemResponse, err error) {
var (
request ApproveItemRequest = ApproveItemRequest{
RelativeId: chanceId,
Type: approveType,
Suggestion: "",
Sign: ApproveSign,
ApproveType: 2,
Uid: header.UserId,
RelativeId: chanceId,
Type: approveType,
Suggestion: "",
Sign: ApproveSign,
ApproveType: 2, //编辑
Uid: header.UserId,
ExtendRelativeId: processId,
}
)
if s.DoRequest(ApproveItem, http.MethodPost, request, &response); err != nil {
log.Error(err)
if err = s.DoRequest(ApproveItem, http.MethodPost, request, &response); err != nil {
return
}
log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", ApproveItem, common.AssertJson(request), common.AssertJson(response)))
return
... ... @@ -229,12 +230,13 @@ type receiverInfo struct {
/*ApproveItem 审批操作*/
type ApproveItemRequest struct {
RelativeId int64 `json:"relativeId"` //关联id
Type int `json:"type"` //审批类型 2 同意 3 驳回 4 撤回 5 直接提交
Suggestion string `json:"suggestion"` //原因/建议
Sign string `json:"sign"` //CHANCE
ApproveType int `json:"approveType"` //1-新增(订单用新增) 2-编辑
Uid int64 `json:"uid"` //用户id
RelativeId int64 `json:"relativeId"` //关联id
Type int `json:"type"` //审批类型 2 同意 3 驳回 4 撤回 5 直接提交
Suggestion string `json:"suggestion"` //原因/建议
Sign string `json:"sign"` //CHANCE
ApproveType int `json:"approveType"` //1-新增(订单用新增) 2-编辑
Uid int64 `json:"uid"` //用户id
ExtendRelativeId int64 `json:"extendRelativeId"` //业务管理id
}
type ApproveItemResponse struct {
Status int `json:"status"` //状态1-待确认2-已确认3-已驳回4-已撤回
... ... @@ -252,3 +254,74 @@ type AppproveProcess struct {
ExtendRelativeId int64 `json:"extendRelativeId"`
Status int `json:"status"`
}
//机会审核
func ChanceApprove(header *protocol.RequestHeader, request *protocol.ChanceApproveRequest) (rsp *protocol.ChanceApproveResponse, err error) {
var (
process *models.AuditFlowProcess
chance *models.Chance
suplusApprove SuplusApprove
approveType int
approveItemResponse ApproveItemResponse
)
//TODO:测试注入
if request.Uid != 0 {
header.UserId = request.Uid
}
approveType = ConverReviewStatus(request.ReviewStatus)
if approveType == 0 {
log.Error("request.reviewStatus error :", request.ReviewStatus)
err = protocol.NewErrWithMessage(2)
return
}
if chance, err = models.GetChanceById(request.ChanceId); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(5101)
return
}
if process, err = models.GetAuditFlowProcessBy(request.ProcessId, header.UserId); err != nil {
log.Error(request.ProcessId, header.UserId, err)
err = protocol.NewErrWithMessage(5202)
return
}
if process.ReviewStatus != protocol.ReviewStatusAuditging {
log.Error(fmt.Sprintf("已被审核 %v", process.Id))
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
}
{
if approveItemResponse.IsApprove == 0 {
}
//更新审批节点审核信息
//更新机会
//发送下一个消息给下一流程的审核人
}
rsp = &protocol.ChanceApproveResponse{}
return
}
//系统审核状态转为审核类型 reviewStatus - > approveType
func ConverReviewStatus(reviewStatus int) (approveType int) {
if reviewStatus == protocol.ReviewStatusPass {
approveType = protocol.ApproveTypePass
} else if reviewStatus == protocol.ReviewStatusReturn {
approveType = protocol.ApproveTypeReject
}
return
}
func ConverTypeToReviewStaus(approveType int) (reviewStatus int) {
if approveType == protocol.ApproveTypePass {
reviewStatus = protocol.ReviewStatusPass
} else if approveType == protocol.ApproveTypeReject {
reviewStatus = protocol.ReviewStatusReturn
}
return
}
... ...
... ... @@ -502,6 +502,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
FlowType: config.FlowType,
ActionType: int(config.ActionType),
EnableStatus: 1,
ReviewStatus: protocol.ReviewStatusAuditging,
}
//if uid==0 && auditConfig.NoApprover==1{//审批人为空 自动通过
// item.
... ...