作者 yangfu

审批修改

@@ -206,7 +206,7 @@ func (this *ChanceController) Templates() { @@ -206,7 +206,7 @@ func (this *ChanceController) Templates() {
206 msg = protocol.NewReturnResponse(chance.Templates(header, request)) 206 msg = protocol.NewReturnResponse(chance.Templates(header, request))
207 } 207 }
208 208
209 -//ChanceSubmit 209 +//ChanceSubmit 提交机会
210 //@router /submit [post] 210 //@router /submit [post]
211 func (this *ChanceController) ChanceSubmit() { 211 func (this *ChanceController) ChanceSubmit() {
212 var msg *protocol.ResponseMessage 212 var msg *protocol.ResponseMessage
@@ -125,7 +125,7 @@ func PrintLogSql(sql string, param ...interface{}) { @@ -125,7 +125,7 @@ func PrintLogSql(sql string, param ...interface{}) {
125 for i := range param { 125 for i := range param {
126 p.WriteString(fmt.Sprintf(parmformat, param[i])) 126 p.WriteString(fmt.Sprintf(parmformat, param[i]))
127 } 127 }
128 - log.Debug(format, sql, p.String()) 128 + log.Debug(fmt.Sprintf(format, sql, p.String()))
129 } 129 }
130 130
131 //ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收 131 //ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收
@@ -11,6 +11,7 @@ type UserCompany struct { @@ -11,6 +11,7 @@ type UserCompany struct {
11 Id int64 `orm:"column(id)" description:"唯一标识"` 11 Id int64 `orm:"column(id)" description:"唯一标识"`
12 CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"` 12 CompanyId int64 `orm:"column(company_id)" description:"表company.id 公司编号"`
13 UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"` 13 UserId int64 `orm:"column(user_id)" description:"表user.id 用户编号"`
  14 + NickName string `orm:"column(nick_name);size(100)" description:"昵称"`
14 DepartmentId int `orm:"column(department_id)" description:"部门id"` 15 DepartmentId int `orm:"column(department_id)" description:"部门id"`
15 PositionId int `orm:"column(position_id)" description:"职位id"` 16 PositionId int `orm:"column(position_id)" description:"职位id"`
16 ChanceTotal int `orm:"column(chance_total)" description:"发表机会数"` 17 ChanceTotal int `orm:"column(chance_total)" description:"发表机会数"`
@@ -104,3 +104,13 @@ func GetUserByUcenterId(uid int64) (v *User, err error) { @@ -104,3 +104,13 @@ func GetUserByUcenterId(uid int64) (v *User, err error) {
104 } 104 }
105 return nil, err 105 return nil, err
106 } 106 }
  107 +
  108 +//根据用户公司编号 获取用户信息
  109 +func GetUserByUcid(ucid int64) (v *User, err error) {
  110 + o := orm.NewOrm()
  111 + 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"
  112 + if err = o.Raw(sql, ucid).QueryRow(&v); err == nil {
  113 + return v, nil
  114 + }
  115 + return nil, err
  116 +}
@@ -14,6 +14,11 @@ const ( @@ -14,6 +14,11 @@ const (
14 AuditBySpecailUser //特殊人员 14 AuditBySpecailUser //特殊人员
15 ) 15 )
16 16
  17 +const (
  18 + ActionTypeOr = 1
  19 + ActionTypeAnd = 2
  20 +)
  21 +
17 //审核类型 22 //审核类型
18 const ( 23 const (
19 FlowTypeNormal = iota + 1 //正常审核流程 24 FlowTypeNormal = iota + 1 //正常审核流程
  1 +package chance
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego"
  6 + "github.com/astaxie/beego/httplib"
  7 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
  8 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  9 + "io/ioutil"
  10 + "net/http"
  11 + "opp/models"
  12 + "opp/protocol"
  13 +
  14 + "encoding/json"
  15 +)
  16 +
  17 +type SuplusApprove struct {
  18 +}
  19 +
  20 +var (
  21 + ErrorRequestSuplus = fmt.Errorf("请求素加后台失败")
  22 +)
  23 +
  24 +var ApproveSign = "CHANCE"
  25 +
  26 +const (
  27 + NewApproveInstance = "/approve-instances/new-approve-instance"
  28 + ApproveItem = "/approve-processes/approve-item"
  29 + ApproveIntegrate = "/approve-processes/integrate"
  30 +)
  31 +
  32 +//新增审批实例
  33 +func (s SuplusApprove) NewApproveInstance(header *protocol.RequestHeader, process []*models.AuditFlowProcess) (err error) {
  34 + var (
  35 + request NewApproveInstanceRequest
  36 + response NewApproveInstanceResponse
  37 + mapApproves map[int]Approve = make(map[int]Approve)
  38 + relativeId int64
  39 + userCompany *models.UserCompany
  40 + )
  41 + if userCompany, err = models.GetUserCompanyByUserId(header.UserId, header.CompanyId); err != nil {
  42 + log.Error(err)
  43 + return
  44 + }
  45 + request = NewApproveInstanceRequest{
  46 + CompanyId: header.CompanyId,
  47 + Approver: userCompany.NickName,
  48 + Uid: userCompany.Id,
  49 + Sign: ApproveSign,
  50 + Type: 1,
  51 + }
  52 + for i := range process {
  53 + var (
  54 + approve Approve
  55 + approveType int //审批类型
  56 + approveWay int //审批方式
  57 + approver *models.User
  58 + )
  59 + item := process[i]
  60 + if relativeId == 0 {
  61 + relativeId = item.ChanceId
  62 + }
  63 + if _, ok := mapApproves[i]; ok {
  64 + approve = mapApproves[i]
  65 + } else {
  66 + approveType = item.AuditFlowType
  67 + if approveType == protocol.AuditBySpecailUser {
  68 + approveType = protocol.AuditByUser
  69 + }
  70 + if item.ActionType == protocol.ActionTypeAnd {
  71 + approveWay = 1 // 会签
  72 + } else {
  73 + approveWay = 2 //或签
  74 + }
  75 + mapApproves[i] = Approve{
  76 + ApproveType: item.AuditFlowType,
  77 + ApproveWay: approveWay,
  78 + }
  79 + }
  80 + if approver, err = models.GetUserByUcid(item.Uid); err != nil {
  81 + log.Error(err)
  82 + return
  83 + }
  84 + approve.ApproveUsers = append(approve.ApproveUsers, ApproveUsers{
  85 + Uid: item.Uid,
  86 + Name: approver.NickName,
  87 + })
  88 + }
  89 + request.RelativeId = relativeId
  90 + for i := 0; i < len(mapApproves); i++ {
  91 + if v, ok := mapApproves[i]; ok {
  92 + request.Approves = append(request.Approves, v)
  93 + }
  94 + }
  95 + if s.DoRequest(NewApproveInstance, http.MethodPost, request, &response); err != nil {
  96 + log.Error(err)
  97 + }
  98 + log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", NewApproveInstance, common.AssertJson(request), common.AssertJson(response)))
  99 + return
  100 +}
  101 +
  102 +//审批操作
  103 +func (s SuplusApprove) ApproveItem(header *protocol.RequestHeader, approveType int, chanceId int64) (response ApproveItemResponse, err error) {
  104 + var (
  105 + request ApproveItemRequest = ApproveItemRequest{
  106 + RelativeId: chanceId,
  107 + Type: approveType,
  108 + Suggestion: "",
  109 + Sign: ApproveSign,
  110 + ApproveType: 2,
  111 + Uid: header.UserId,
  112 + }
  113 + )
  114 + if s.DoRequest(ApproveItem, http.MethodPost, request, &response); err != nil {
  115 + log.Error(err)
  116 + }
  117 + log.Info(fmt.Sprintf("success request suplus-approve:%v request:%v response:%v", ApproveItem, common.AssertJson(request), common.AssertJson(response)))
  118 + return
  119 +}
  120 +
  121 +//审批列表
  122 +func (s SuplusApprove) ApproveIntegrate(header *protocol.RequestHeader, chanceId int64) (response ApproveIntegrateResponse, err error) {
  123 + var ()
  124 + url := fmt.Sprintf("%v?sign=%v&relativeId=%v", ApproveIntegrate, ApproveSign, chanceId)
  125 + if s.DoRequest(url, http.MethodGet, nil, &response); err != nil {
  126 + log.Error(err)
  127 + }
  128 + log.Info(fmt.Sprintf("success request suplus-approve:%v response:%v", url, common.AssertJson(response)))
  129 + return
  130 +}
  131 +
  132 +//请求
  133 +func (s SuplusApprove) DoRequest(method string, methodType string, request interface{}, response interface{}) (err error) {
  134 + var (
  135 + httpRsp *http.Response
  136 + httpReq *httplib.BeegoHTTPRequest
  137 + url = beego.AppConfig.String("suplus_host") + method
  138 + data []byte
  139 + message protocol.Message
  140 + )
  141 + if methodType == http.MethodPost {
  142 + httpReq = httplib.Post(url)
  143 + } else if methodType == http.MethodGet {
  144 + httpReq = httplib.Get(url)
  145 + }
  146 + if request != nil {
  147 + httpReq.JSONBody(request)
  148 + }
  149 + if httpRsp, err = httpReq.DoRequest(); err != nil {
  150 + log.Error(err)
  151 + return
  152 + }
  153 + data, err = ioutil.ReadAll(httpRsp.Body)
  154 + defer httpRsp.Body.Close()
  155 + if err != nil {
  156 + log.Error(err)
  157 + return
  158 + }
  159 + if err = json.Unmarshal(data, &message); err != nil {
  160 + log.Debug(url, "response:", string(data))
  161 + log.Error(err)
  162 + return
  163 + }
  164 + if message.Errno != 0 {
  165 + err = fmt.Errorf("request-%v response-code:%v msg:%v", url, message.Errno, message.Errmsg)
  166 + }
  167 + var responseData string
  168 + if len(data) > 500 {
  169 + responseData = string(data[:200])
  170 + } else {
  171 + responseData = string(data)
  172 + }
  173 + if err = json.Unmarshal(message.Data, &response); err != nil {
  174 + log.Error(err)
  175 + return
  176 + }
  177 + log.Debug(fmt.Sprintf("request-%v request:%v rsp:%v", url, request, responseData))
  178 + return
  179 +}
  180 +
  181 +/*NewApproveInstance 新增审批实例*/
  182 +type NewApproveInstanceRequest struct {
  183 + Approves []Approve `json:"approves"` //审批节点列表
  184 + CompanyId int64 `json:"companyId"` //公司id
  185 + Approver string `json:"approver"` //提交人
  186 + Uid int64 `json:"uid"` //提交人id
  187 + Sign string `json:"sign"` //标识 ORDER-订单 ELSERK-其他入库 CHANCE-机会
  188 + Type int `json:"type"` //1-新增 2-编辑
  189 + RelativeId int64 `json:"relativeId"` //关联id
  190 +
  191 +}
  192 +type NewApproveInstanceResponse struct {
  193 + protocol.ErrorCode
  194 + Data []string `json:"data"`
  195 +}
  196 +
  197 +//审批节点
  198 +type Approve struct {
  199 + ApproveWay int `json:"approveWay"` //审批方式 1 会签 2 或签 3 发起人从角色成员中自选
  200 + ApproveType int `json:"approveType"` //审批类型 1 业务区域负责人 2 指定成员 3 角色
  201 + ApproveUsers []ApproveUsers `json:"approveUsers"` //审批人
  202 +}
  203 +
  204 +//审批人
  205 +type ApproveUsers struct {
  206 + Uid int64 `json:"uid"` //用户id
  207 + Name string `json:"name"` //用户名
  208 + IsDefault int `json:"isDefault"` //1 是默认 0 不是
  209 + RoleName string `json:"roleName"` //角色名/负责人
  210 + RoleId string `json:"roleId"` //角色id
  211 + ParentIds []int `json:"parentIds"`
  212 +}
  213 +
  214 +/*ApproveItem 审批操作*/
  215 +type ApproveItemRequest struct {
  216 + RelativeId int64 `json:"relativeId"` //关联id
  217 + Type int `json:"type"` //审批类型 2 同意 3 驳回 4 撤回 5 直接提交
  218 + Suggestion string `json:"suggestion"` //原因/建议
  219 + Sign string `json:"sign"` //CHANCE
  220 + ApproveType int `json:"approveType"` //1-新增(订单用新增) 2-编辑
  221 + Uid int64 `json:"uid"` //用户id
  222 +}
  223 +type ApproveItemResponse struct {
  224 + Status int `json:"status"` //状态1-待确认2-已确认3-已驳回4-已撤回
  225 + ApproveStatus int `json:"approveStatus"` //审批状态0 待审批 1 审批中 2 同意 3 驳回 4 提交订单 5 已被其他人处理 (0这个状态不存在审批后)
  226 + IsApprove int `json:"isApprove"` //是否需要审批 1是 0 否
  227 +}
  228 +
  229 +/*ApproveIntegrate 审核列表*/
  230 +type ApproveIntegrateRequest struct {
  231 +}
  232 +type ApproveIntegrateResponse struct {
  233 +}
@@ -244,6 +244,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit @@ -244,6 +244,7 @@ func ChanceSubmit(header *protocol.RequestHeader, request *protocol.ChanceSubmit
244 CreateAt: time.Now(), 244 CreateAt: time.Now(),
245 UpdateAt: time.Now(), 245 UpdateAt: time.Now(),
246 AuditLevel: 1, 246 AuditLevel: 1,
  247 + ReviewStatus: protocol.ReviewStatusAuditging,
247 DepartmentId: request.RelatedDepartment, 248 DepartmentId: request.RelatedDepartment,
248 } 249 }
249 if _, err = orm.Insert(chance); err != nil { 250 if _, err = orm.Insert(chance); err != nil {
@@ -580,8 +581,9 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt @@ -580,8 +581,9 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt
580 for i := range chanceType { 581 for i := range chanceType {
581 item := chanceType[i] 582 item := chanceType[i]
582 rsp.List = append(rsp.List, protocol.ChanceTotalItem{ 583 rsp.List = append(rsp.List, protocol.ChanceTotalItem{
583 - Id: item.Id,  
584 - Name: item.Name, 584 + Id: item.Id,
  585 + Name: item.Name,
  586 + Total: i * 2,
585 }) 587 })
586 } 588 }
587 return 589 return
@@ -91,7 +91,6 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo @@ -91,7 +91,6 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
91 user *models.User 91 user *models.User
92 //message *protocol.Message 92 //message *protocol.Message
93 //getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{} 93 //getUserRequest *protocol.UCenterGetUserRequest = &protocol.UCenterGetUserRequest{}
94 - //getUserResponse *protocol.UCenter_GetUserResponse  
95 result bool 94 result bool
96 ) 95 )
97 if len(request.NewPwd) < 6 { 96 if len(request.NewPwd) < 6 {
@@ -150,6 +149,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass @@ -150,6 +149,7 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
150 user *models.User 149 user *models.User
151 loginResponse *protocol.UCenterGetUserResponse //UserCenterLoginResponse 150 loginResponse *protocol.UCenterGetUserResponse //UserCenterLoginResponse
152 ) 151 )
  152 + rsp = &protocol.ChangePasswordResponse{}
153 if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) { 153 if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
154 err = protocol.NewErrWithMessage(2026) 154 err = protocol.NewErrWithMessage(2026)
155 return 155 return