作者 tangxvhui

补充机会详情

... ... @@ -142,3 +142,29 @@ func (c *AuditController) AllowForbidAudit() {
msg = protocol.NewReturnResponse(nil, err)
return
}
//GetChanceReviseLog
//@router /v1/audit/revise/info
func (c *AuditController) GetChanceReviseLog() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
FlowLogId int64 `json:"flow_log_id"`
ChanceId string `json:"chance_id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
chanceId, _ := strconv.ParseInt(param.ChanceId, 10, 64)
companyId := c.GetCompanyId()
rspData, err := serveaudit.GetChanceReviseLog(param.FlowLogId, chanceId, companyId)
msg = protocol.NewReturnResponse(rspData, err)
return
}
// GetChanceReviseLog
... ...
... ... @@ -183,3 +183,21 @@ func (c *CommonController) SelectorRoleUser() {
msg = protocol.NewReturnResponse(list, err)
return
}
//SelectorChanceType 获取机会类型列表
func (c *CommonController) SelectorChanceType() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
companyid := c.GetCompanyId()
templatelist := servecommon.SelectGetTemplateList(companyid)
chanceTypeList := servecommon.SeleteGetChanceTypeList(companyid)
data := map[string]interface{}{
"template": templatelist,
"chance_type": chanceTypeList,
}
msg = protocol.NewReturnResponse(data, nil)
return
}
... ...
package models
import (
"encoding/json"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceReviseLog struct {
Id int64 `orm:"column(id);pk" description:"id 主键"`
ChanceId int64 `orm:"column(chance_id)" description:"机会编号"`
UserCompanyId int64 `orm:"column(user_company_id);null" description:"用户编号 编辑机会的人"`
Data string `orm:"column(data);null" description:"机会数据"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
AuditFlowLogId int64 `orm:"column(audit_flow_log_id);null" description:"表audit_flow_log.id "`
}
func (t *ChanceReviseLog) TableName() string {
return "chance_revise_log"
}
func init() {
orm.RegisterModel(new(ChanceReviseLog))
}
type ReviseContentsItem struct {
Content string `json:"content"`
}
type ChanceReviseLogData struct {
ReviseContents []ReviseContentsItem `json:"reviseContents"`
Speechs []ChanceDataSpeechs `json:"speechs"`
Pictures []ChanceDataImage `json:"pictures"`
Videos []ChanceDataVideos `json:"videos"`
}
// GetChanceReviseLogById retrieves ChanceReviseLog by Id. Returns error if
// Id doesn't exist
func GetChanceReviseLogById(id int64) (v *ChanceReviseLog, err error) {
o := orm.NewOrm()
v = &ChanceReviseLog{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
func GetChanceReviseLogData(flowLogId int64) (*ChanceReviseLog, *ChanceReviseLogData, error) {
o := orm.NewOrm()
var (
err error
)
reviseLog := &ChanceReviseLog{}
err = o.QueryTable(&ChanceReviseLog{}).
Filter("audit_flow_log_id", flowLogId).
One(reviseLog)
if err != nil {
return nil, nil, err
}
reviseLogData := &ChanceReviseLogData{
ReviseContents: make([]ReviseContentsItem, 0),
Speechs: make([]ChanceDataSpeechs, 0),
Pictures: make([]ChanceDataImage, 0),
Videos: make([]ChanceDataVideos, 0),
}
json.Unmarshal([]byte(reviseLog.Data), reviseLogData)
return reviseLog, reviseLogData, err
}
... ...
... ... @@ -275,4 +275,5 @@ type ChanceFlowLog struct {
CreateAt string `json:"create_at" orm:"column(create_at)"`
Content string `json:"content" orm:"column(content)"`
NickName string `json:"nick_name" orm:"column(nick_name)"`
Code int `json:"code" orm:"column(code)"`
}
... ...
... ... @@ -75,6 +75,7 @@ func init() {
beego.NSRouter("/user_and_department", &controllers.CommonController{}, "post:SelectorUserAndDepart"),
beego.NSRouter("/default_image", &controllers.CommonController{}, "post:DefaultImage"),
beego.NSRouter("/role/user", &controllers.CommonController{}, "post:SelectorRoleUser"),
beego.NSRouter("/chance_type", &controllers.CommonController{}, "post:SelectorChanceType"),
),
beego.NSNamespace("/template",
beego.NSRouter("/add", &controllers.TemplateController{}, "post:TemplateAdd"),
... ... @@ -102,6 +103,7 @@ func init() {
beego.NSRouter("/list/before", &controllers.AuditController{}, "post:AuditListBefore"),
beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"),
beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"),
beego.NSRouter("/revise/info", &controllers.AuditController{}, "post:GetChanceReviseLog"),
),
beego.NSNamespace("/rank",
beego.NSRouter("/type/list", &controllers.RankController{}, "post:GetRankType"),
... ...
... ... @@ -425,7 +425,7 @@ func getAuditFlowLog(chanceid int64) ([]protocol.ChanceFlowLog, error) {
flowLogs = make([]protocol.ChanceFlowLog, 0)
err error
)
const datasql string = `SELECT a.chance_id,a.content,a.create_at,c.nick_name
const datasql string = `SELECT a.chance_id,a.content,a.create_at,c.nick_name,a.code
FROM audit_flow_log AS a
LEFT JOIN user_company AS b ON a.approve_user_id=b.id
LEFT JOIN user AS c ON b.user_id = c.id
... ... @@ -525,3 +525,50 @@ func GetPermissionInAuditPage(userid int64, companyid int64) serverabc.OptionOpp
}
return option
}
type ChanceReviseLogInfo struct {
UserName string `json:"user_name"`
UserComapnyId int64 `json:"user_company_id"`
CreateTime string `json:"create_time"`
models.ChanceReviseLogData
}
//GetChanceReviseLog 获取对机会的操作记录,补充机会的详情
func GetChanceReviseLog(flowLogId int64, chanceId int64, companyId int64) (*ChanceReviseLogInfo, error) {
var (
reviseLog *models.ChanceReviseLog
reviseLogData *models.ChanceReviseLogData
usercompanyData *models.UserCompany
chanceData *models.Chance
err error
)
chanceData, err = models.GetChanceById(chanceId)
if err != nil {
log.Error("获取机会数据chance失败:%s", err)
return nil, protocol.NewErrWithMessage("1")
}
if chanceData.CompanyId != companyId {
log.Error("机会的公司不匹配")
}
reviseLog, reviseLogData, err = models.GetChanceReviseLogData(flowLogId)
if err != nil {
log.Error("获取chance_revise_log失败,err:%s", err)
return nil, protocol.NewErrWithMessage("1")
}
if reviseLog.ChanceId != chanceId {
log.Error("日志与机会不匹配")
return nil, protocol.NewErrWithMessage("1")
}
rspData := &ChanceReviseLogInfo{
UserComapnyId: reviseLog.UserCompanyId,
CreateTime: reviseLog.CreateAt.Format("2006-01-02 15:04:05"),
ChanceReviseLogData: *reviseLogData,
}
usercompanyData, err = models.GetUserCompanyById(reviseLog.UserCompanyId)
if err != nil {
log.Error("获取用户数据user_company失败;%s", err)
} else {
rspData.UserName = usercompanyData.NickName
}
return rspData, nil
}
... ...