作者 yangfu

用户信息修改

... ... @@ -273,6 +273,48 @@ func (this *ChanceController) MySubmitChance() {
msg = protocol.NewReturnResponse(chance.MySubmitChance(header, request))
}
//ChanceDetail 机会详情
//@router /chanceDetail [post]
func (this *ChanceController) ChanceDetail() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceDetailRequest
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.ChanceDetail(header, request))
}
//ChanceDelete 机会删除
//@router /chanceDelete [post]
func (this *ChanceController) ChanceDelete() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.ChanceDeleteRequest
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.ChanceDelete(header, request))
}
//ChanceApprove 机会审核
//func(this *ChanceController)ChanceApprove(){
// var msg *protocol.ResponseMessage
... ...
... ... @@ -8,12 +8,13 @@ import (
)
type UserDepartment struct {
Id int64 `orm:"column(id);auto" description:"主键"`
UserId int64 `orm:"column(user_id)" description:"用户id"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
DepartmentId int `orm:"column(department_id)" description:"部门id"`
CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
Id int64 `orm:"column(id);auto" description:"主键"`
//UserId int64 `orm:"column(user_id)" description:"用户id"`
CompanyId int `orm:"column(company_id)" description:"公司id"`
UserCompanyId int64 `orm:"column(user_company_id)" description:"用户公司id"`
DepartmentId int `orm:"column(department_id)" description:"部门id"`
CreateTime time.Time `orm:"column(create_time);type(timestamp);null" description:"创建时间"`
EnableStatus int8 `orm:"column(enable_status)" description:"是否有效"`
}
func (t *UserDepartment) TableName() string {
... ...
... ... @@ -8,12 +8,13 @@ import (
)
type UserPosition struct {
Id int `orm:"column(id);pk" description:"唯一键值"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
PositionId int `orm:"column(position_id)" description:"表position.id 职位编号"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 1:有效 0:无效"`
Id int `orm:"column(id);pk" description:"唯一键值"`
//UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
PositionId int `orm:"column(position_id)" description:"表position.id 职位编号"`
UserCompanyId int64 `orm:"column(user_company_id)" description:"用户公司id"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"`
CompanyId int `orm:"column(company_id)" description:"表company.id 公司编号"`
EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 1:有效 0:无效"`
}
func (t *UserPosition) TableName() string {
... ...
... ... @@ -201,3 +201,19 @@ type ChanceItem struct {
Pictures []Picture `json:"pictures"`
Videos []Video `json:"videos"`
}
/*ChanceDetail 机会详情*/
type ChanceDetailRequest struct {
Id int64 `json:"id"` //机会编号
}
type ChanceDetailResponse struct {
ChanceDetail ChanceItem `json:"chanceDetail"`
ApproveProcess interface{} `json:"approveProcess"`
}
/*ChanceDelete 机会删除*/
type ChanceDeleteRequest struct {
Id int64 `json:"id"` //机会编号
}
type ChanceDeleteResponse struct {
}
... ...
package protocol
type ApproveProcess struct {
//RelativeId int64 `json:"relativeId"`
Uid int64 `json:"uid"`
Name string `json:"name"`
ApproveWay int `json:"approveWay"` //审核方式
Status int `json:"status"` //状态
Active int `json:"active"`
ApproveTime int64 `json:"approveTime"` //审核时间
}
... ...
... ... @@ -9,6 +9,7 @@ var errmessge ErrorMap = map[int]string{
1: "系统异常",
2: "参数错误",
3: "统一用户中心操作异常",
5: "繁忙,请稍后再试",
101: "clientId或clientSecret无效",
113: "签名验证失败",
1009: "验证码已失效",
... ... @@ -30,7 +31,12 @@ var errmessge ErrorMap = map[int]string{
4141: "accessToken过期或无效,需要进行重新获取令牌",
4142: "Uuid已存在,请求失败",
4201: "无该公司",
5000: "繁忙,请稍后再试",
//机会相关
5101: "该机会已被删除",
//机会审批相关
5201: "该机会模板未配置审批人,请选择其他模板",
}
/*MessageCenter */
... ...
... ... @@ -73,6 +73,7 @@ type User struct {
type Company struct {
Id int64 `json:"id"`
Name string `json:"name"`
CId int64 `json:"cid"` //统一用户中心公司编号
}
//部门
... ...
... ... @@ -25,6 +25,9 @@ func GetUserBaseInfoAggregation(id int64, companyId int64) (v *protocol.UserBase
log.Error(err)
return
}
if len(v.UserCompany.NickName) > 0 {
v.User.NickName = v.UserCompany.NickName //公司里面的用户名称
}
wg.Add(3)
go func() {
defer wg.Done()
... ...
... ... @@ -14,9 +14,6 @@ import (
"encoding/json"
)
type SuplusApprove struct {
}
var (
ErrorRequestSuplus = fmt.Errorf("请求素加后台失败")
)
... ... @@ -29,12 +26,15 @@ const (
ApproveIntegrate = "/approve-processes/integrate"
)
type SuplusApprove struct {
}
//新增审批实例
func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, process []*models.AuditFlowProcess) (err error) {
var (
request NewApproveInstanceRequest
response NewApproveInstanceResponse
mapApproves map[int]Approve = make(map[int]Approve)
mapApproves map[int]*Approve = make(map[int]*Approve)
relativeId int64
userCompany *models.UserCompany
)
... ... @@ -51,7 +51,7 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
}
for i := range process {
var (
approve Approve
approve *Approve
approveType int //审批类型
approveWay int //审批方式
approver *models.User
... ... @@ -72,10 +72,11 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
} else {
approveWay = 2 //或签
}
mapApproves[i] = Approve{
approve = &Approve{
ApproveType: item.AuditFlowType,
ApproveWay: approveWay,
}
mapApproves[i] = approve
}
if approver, err = models.GetUserByUcid(item.Uid); err != nil {
log.Error(err)
... ... @@ -84,6 +85,8 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{
Uid: item.Uid,
Name: approver.NickName,
//RoleId:5,
RoleId: 0,
})
}
request.RelativeId = relativeId
... ... @@ -92,10 +95,9 @@ func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, proces
request.Approves = append(request.Approves, v)
}
}
if s.DoRequest(NewApproveInstance, http.MethodPost, request, &response); err != nil {
if err = s.DoRequest(NewApproveInstance, http.MethodPost, request, &response); err != nil {
log.Error(err)
}
log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", NewApproveInstance, common.AssertJson(request), common.AssertJson(response)))
return
}
... ... @@ -162,7 +164,8 @@ func (s SuplusApprove) DoRequest(method string, methodType string, request inter
return
}
if message.Errno != 0 {
err = fmt.Errorf("request-%v response-code:%v msg:%v", url, message.Errno, message.Errmsg)
err = fmt.Errorf("request-%v request-%v response-code:%v msg:%v", url, common.AssertJson(request), message.Errno, message.Errmsg)
return
}
var responseData string
if len(data) > 500 {
... ... @@ -170,29 +173,27 @@ func (s SuplusApprove) DoRequest(method string, methodType string, request inter
} else {
responseData = string(data)
}
if err = json.Unmarshal(message.Data, &response); err != nil {
log.Error(err)
if e := json.Unmarshal(message.Data, &response); e != nil {
log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, common.AssertJson(request), string(responseData)))
log.Error(e)
return
}
log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, request, responseData))
log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, common.AssertJson(request), common.AssertJson(response)))
return
}
/*NewApproveInstance 新增审批实例*/
type NewApproveInstanceRequest struct {
Approves []Approve `json:"approves"` //审批节点列表
CompanyId int64 `json:"companyId"` //公司id
Approver string `json:"approver"` //提交人
Uid int64 `json:"uid"` //提交人id
Sign string `json:"sign"` //标识 ORDER-订单 ELSERK-其他入库 CHANCE-机会
Type int `json:"type"` //1-新增 2-编辑
RelativeId int64 `json:"relativeId"` //关联id
Approves []*Approve `json:"approves"` //审批节点列表
CompanyId int64 `json:"companyId"` //公司id
Approver string `json:"approver"` //提交人
Uid int64 `json:"uid"` //提交人id
Sign string `json:"sign"` //标识 ORDER-订单 ELSERK-其他入库 CHANCE-机会
Type int `json:"type"` //1-新增 2-编辑
RelativeId int64 `json:"relativeId"` //关联id
}
type NewApproveInstanceResponse struct {
protocol.ErrorCode
Data []string `json:"data"`
}
type NewApproveInstanceResponse interface{}
//审批节点
type Approve struct {
... ... @@ -207,7 +208,7 @@ type ApproveUsers struct {
Name string `json:"name"` //用户名
IsDefault int `json:"isDefault"` //1 是默认 0 不是
RoleName string `json:"roleName"` //角色名/负责人
RoleId string `json:"roleId"` //角色id
RoleId int `json:"roleId"` //角色id
ParentIds []int `json:"parentIds"`
}
... ... @@ -231,3 +232,8 @@ type ApproveIntegrateRequest struct {
}
type ApproveIntegrateResponse struct {
}
type AppproveProcess struct {
ExtendRelativeId int64 `json:"extendRelativeId"`
Status int `json:"status"`
}
... ...
... ... @@ -215,10 +215,11 @@ func checkTemplateIsVisible(header *protocol.RequestHeader, template *models.Aud
//提交机会
func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmitRequest) (rsp *protocol.ChanceSubmitResponse, err error) {
var (
template *models.AuditTemplate
chance *models.Chance
auditConfig *protocol.AuditConfig
auditFlows []*models.AuditFlowProcess
template *models.AuditTemplate
chance *models.Chance
auditConfig *protocol.AuditConfig
auditFlows []*models.AuditFlowProcess
suplusApprove SuplusApprove
)
//1.模板是否存在
if template, err = models.GetAuditTemplateById(request.AuditTemplateId); err != nil {
... ... @@ -267,6 +268,14 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
return
}
}
if len(auditFlows) > 0 {
if err = suplusApprove.NewApproveInstance(header, auditFlows); err != nil {
log.Error(fmt.Sprintf("uid:%v", header.UserId), "request suplus-approve.NewApproveInstance err", err)
orm.Rollback()
return
}
}
//6.文件
{
data := &models.ChanceData{
... ... @@ -403,6 +412,11 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
log.Error(err)
return
}
if len(configs) == 0 {
//err = protocol.NewErrWithMessage(5201) //未配置审核人
//log.Error(err)
return
}
//1.检查是否是特殊审核人
for i := range configs {
... ... @@ -431,7 +445,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
if groupId == 0 {
log.Error(fmt.Sprintf("group_id=0 template_id:%v", templateId))
//log.Error(err)
log.Error(err)
return
}
... ... @@ -478,7 +492,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
uid = company.AdminId
}
if uid == header.Uid { //审核人自己 转交给管理员
log.Info(fmt.Sprintf("GenAuditFlowProcess:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
log.Info(fmt.Sprintf("生成机会审批流-转给管理员:chance_id:%v audit_level:%v audit_user:%v -> admin:%v", chanceId, config.Level, uid, company.AdminId))
uid = company.AdminId
}
item := &models.AuditFlowProcess{
... ... @@ -500,7 +514,7 @@ func GenAuditFlowProcess(header *protocol.RequestHeader, chanceId int64, templat
item.IsActive = 1
//通知 user_msg
}
log.Info(fmt.Sprintf("GenAuditFlowProcess:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType)))
log.Info(fmt.Sprintf("生成机会审批流:chance_id:%v audit_id:%v audit_level:%v audit_user:%v action_type:%v", chanceId, item.Id, config.Level, uid, resolveActionType(config.ActionType)))
v = append(v, item)
}
}
... ... @@ -634,3 +648,57 @@ func jsonUnmarshal(jsonData string, v interface{}) {
log.Error("json.unmarshal error data:", jsonData, e)
}
}
//机会详情
func ChanceDetail(header *protocol.RequestHeader, request *protocol.ChanceDetailRequest) (rsp *protocol.ChanceDetailResponse, err error) {
var (
chance *models.Chance
chanceData *models.ChanceData
provider *protocol.BaseUserInfo
)
//检查是否可见
if provider, err = agg.GetUserBaseInfo(chance.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
if chance, err = models.GetChanceById(request.Id); err != nil {
if err == orm.ErrNoRows {
err = protocol.NewErrWithMessage(5101)
return
}
log.Error(err)
return
}
item := protocol.ChanceItem{
Id: chance.Id,
Provider: provider,
CreateTime: chance.CreateAt.Unix() * 1000,
}
jsonUnmarshal(chance.SourceContent, &item.FormList)
if chanceData, err = models.GetChanceDataByChanceId(chance.Id); err == nil {
jsonUnmarshal(chanceData.Images, &item.Pictures)
jsonUnmarshal(chanceData.Speechs, &item.Speechs)
jsonUnmarshal(chanceData.Videos, &item.Videos)
}
rsp = &protocol.ChanceDetailResponse{}
return
}
//机会删除
func ChanceDelete(header *protocol.RequestHeader, request *protocol.ChanceDeleteRequest) (rsp *protocol.ChanceDeleteResponse, err error) {
var (
chance *models.Chance
)
if chance, err = models.GetChanceById(request.Id); err != nil {
if err == orm.ErrNoRows {
err = protocol.NewErrWithMessage(5101)
return
}
log.Error(err)
return
}
if chance != nil {
}
rsp = &protocol.ChanceDeleteResponse{}
return
}
... ...
... ... @@ -335,6 +335,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
Company: protocol.Company{
Id: userBaseAgg.Company.Id,
Name: userBaseAgg.Company.Name,
CId: userBaseAgg.Company.UserCenterId,
},
},
}
... ... @@ -342,6 +343,7 @@ func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest)
rsp.User.Companys = append(rsp.User.Companys, protocol.Company{
Id: companys[i].Id,
Name: companys[i].Name,
CId: companys[i].UserCenterId,
})
}
if topDep := agg.GetTopDepartment(userBaseAgg.Department); topDep.DepartmentId != 0 {
... ...