作者 yangfu

审批修改

... ... @@ -206,7 +206,7 @@ func (this *ChanceController) Templates() {
msg = protocol.NewReturnResponse(chance.Templates(header, request))
}
//ChanceSubmit
//ChanceSubmit 提交机会
//@router /submit [post]
func (this *ChanceController) ChanceSubmit() {
var msg *protocol.ResponseMessage
... ...
... ... @@ -125,7 +125,7 @@ func PrintLogSql(sql string, param ...interface{}) {
for i := range param {
p.WriteString(fmt.Sprintf(parmformat, param[i]))
}
log.Debug(format, sql, p.String())
log.Debug(fmt.Sprintf(format, sql, p.String()))
}
//ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收
... ...
... ... @@ -11,6 +11,7 @@ type UserCompany struct {
Id int64 `orm:"column(id)" description:"唯一标识"`
CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
NickName string `orm:"column(nick_name);size(100)" description:"昵称"`
DepartmentId int `orm:"column(department_id)" description:"部门id"`
PositionId int `orm:"column(position_id)" description:"职位id"`
ChanceTotal int `orm:"column(chance_total)" description:"发表机会数"`
... ...
... ... @@ -104,3 +104,13 @@ func GetUserByUcenterId(uid int64) (v *User, err error) {
}
return nil, err
}
//根据用户公司编号 获取用户信息
func GetUserByUcid(ucid int64) (v *User, err error) {
o := orm.NewOrm()
sql := "select id,nick_name from `user` where id = (select user_id from user_company where id=? and enable_status=1) and enable_status=1"
if err = o.Raw(sql, ucid).QueryRow(&v); err == nil {
return v, nil
}
return nil, err
}
... ...
... ... @@ -14,6 +14,11 @@ const (
AuditBySpecailUser //特殊人员
)
const (
ActionTypeOr = 1
ActionTypeAnd = 2
)
//审核类型
const (
FlowTypeNormal = iota + 1 //正常审核流程
... ...
package chance
import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/httplib"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"io/ioutil"
"net/http"
"opp/models"
"opp/protocol"
"encoding/json"
)
type SuplusApprove struct {
}
var (
ErrorRequestSuplus = fmt.Errorf("请求素加后台失败")
)
var ApproveSign = "CHANCE"
const (
NewApproveInstance = "/approve-instances/new-approve-instance"
ApproveItem = "/approve-processes/approve-item"
ApproveIntegrate = "/approve-processes/integrate"
)
//新增审批实例
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)
relativeId int64
userCompany *models.UserCompany
)
if userCompany, err = models.GetUserCompanyByUserId(header.UserId, header.CompanyId); err != nil {
log.Error(err)
return
}
request = NewApproveInstanceRequest{
CompanyId: header.CompanyId,
Approver: userCompany.NickName,
Uid: userCompany.Id,
Sign: ApproveSign,
Type: 1,
}
for i := range process {
var (
approve Approve
approveType int //审批类型
approveWay int //审批方式
approver *models.User
)
item := process[i]
if relativeId == 0 {
relativeId = item.ChanceId
}
if _, ok := mapApproves[i]; ok {
approve = mapApproves[i]
} else {
approveType = item.AuditFlowType
if approveType == protocol.AuditBySpecailUser {
approveType = protocol.AuditByUser
}
if item.ActionType == protocol.ActionTypeAnd {
approveWay = 1 // 会签
} else {
approveWay = 2 //或签
}
mapApproves[i] = Approve{
ApproveType: item.AuditFlowType,
ApproveWay: approveWay,
}
}
if approver, err = models.GetUserByUcid(item.Uid); err != nil {
log.Error(err)
return
}
approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{
Uid: item.Uid,
Name: approver.NickName,
})
}
request.RelativeId = relativeId
for i := 0; i < len(mapApproves); i++ {
if v, ok := mapApproves[i]; ok {
request.Approves = append(request.Approves, v)
}
}
if 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
}
//审批操作
func (s SuplusApprove) ApproveItem(header *protocol.RequestHeader, approveType int, chanceId int64) (response ApproveItemResponse, err error) {
var (
request ApproveItemRequest = ApproveItemRequest{
RelativeId: chanceId,
Type: approveType,
Suggestion: "",
Sign: ApproveSign,
ApproveType: 2,
Uid: header.UserId,
}
)
if s.DoRequest(ApproveItem, http.MethodPost, request, &response); err != nil {
log.Error(err)
}
log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", ApproveItem, common.AssertJson(request), common.AssertJson(response)))
return
}
//审批列表
func (s SuplusApprove) ApproveIntegrate(header *protocol.RequestHeader, chanceId int64) (response ApproveIntegrateResponse, err error) {
var ()
url := fmt.Sprintf("%v?sign=%v&relativeId=%v", ApproveIntegrate, ApproveSign, chanceId)
if s.DoRequest(url, http.MethodGet, nil, &response); err != nil {
log.Error(err)
}
log.Info(fmt.Sprintf("success request suplus-approve:%v response:%v", url, common.AssertJson(response)))
return
}
//请求
func (s SuplusApprove) DoRequest(method string, methodType string, request interface{}, response interface{}) (err error) {
var (
httpRsp *http.Response
httpReq *httplib.BeegoHTTPRequest
url = beego.AppConfig.String("suplus_host") + method
data []byte
message protocol.Message
)
if methodType == http.MethodPost {
httpReq = httplib.Post(url)
} else if methodType == http.MethodGet {
httpReq = httplib.Get(url)
}
if request != nil {
httpReq.JSONBody(request)
}
if httpRsp, err = httpReq.DoRequest(); err != nil {
log.Error(err)
return
}
data, err = ioutil.ReadAll(httpRsp.Body)
defer httpRsp.Body.Close()
if err != nil {
log.Error(err)
return
}
if err = json.Unmarshal(data, &message); err != nil {
log.Debug(url, "response:", string(data))
log.Error(err)
return
}
if message.Errno != 0 {
err = fmt.Errorf("request-%v response-code:%v msg:%v", url, message.Errno, message.Errmsg)
}
var responseData string
if len(data) > 500 {
responseData = string(data[:200])
} else {
responseData = string(data)
}
if err = json.Unmarshal(message.Data, &response); err != nil {
log.Error(err)
return
}
log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, request, responseData))
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
}
type NewApproveInstanceResponse struct {
protocol.ErrorCode
Data []string `json:"data"`
}
//审批节点
type Approve struct {
ApproveWay int `json:"approveWay"` //审批方式 1 会签 2 或签 3 发起人从角色成员中自选
ApproveType int `json:"approveType"` //审批类型 1 业务区域负责人 2 指定成员 3 角色
ApproveUsers []ApproveUsers `json:"approveUsers"` //审批人
}
//审批人
type ApproveUsers struct {
Uid int64 `json:"uid"` //用户id
Name string `json:"name"` //用户名
IsDefault int `json:"isDefault"` //1 是默认 0 不是
RoleName string `json:"roleName"` //角色名/负责人
RoleId string `json:"roleId"` //角色id
ParentIds []int `json:"parentIds"`
}
/*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
}
type ApproveItemResponse struct {
Status int `json:"status"` //状态1-待确认2-已确认3-已驳回4-已撤回
ApproveStatus int `json:"approveStatus"` //审批状态0 待审批 1 审批中 2 同意 3 驳回 4 提交订单 5 已被其他人处理 (0这个状态不存在审批后)
IsApprove int `json:"isApprove"` //是否需要审批 1是 0 否
}
/*ApproveIntegrate 审核列表*/
type ApproveIntegrateRequest struct {
}
type ApproveIntegrateResponse struct {
}
... ...
... ... @@ -244,6 +244,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
CreateAt: time.Now(),
UpdateAt: time.Now(),
AuditLevel: 1,
ReviewStatus: protocol.ReviewStatusAuditging,
DepartmentId: request.RelatedDepartment,
}
if _, err = orm.Insert(chance); err != nil {
... ... @@ -580,8 +581,9 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
for i := range chanceType {
item := chanceType[i]
rsp.List = append(rsp.List, protocol.ChanceTotalItem{
Id: item.Id,
Name: item.Name,
Id: item.Id,
Name: item.Name,
Total: i * 2,
})
}
return
... ...
... ... @@ -91,7 +91,6 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
user *models.User
//message *protocol.Message
//getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{}
//getUserResponse *protocol.UCenter_GetUserResponse
result bool
)
if len(request.NewPwd) < 6 {
... ... @@ -150,6 +149,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
user *models.User
loginResponse *protocol.UCenterGetUserResponse //UserCenterLoginResponse
)
rsp = &protocol.ChangePasswordResponse{}
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
err = protocol.NewErrWithMessage(2026)
return
... ...