作者 yangfu

增加 提交筛选结果

... ... @@ -718,3 +718,24 @@ func (this *ChanceController) SiftingResults() {
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(chance.SiftingResults(header, request))
}
//SubmitChecks 提交自查
//@router /submitSiftingResult [post]
func (this *ChanceController) SubmitChecks() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.SubmitChecksRequest
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.SubmitChecks(header, request))
}
... ...
... ... @@ -33,8 +33,8 @@ type AuditFlowProcess struct {
ApproveMessage string `orm:"column(approve_message);size(50)" description:"审核消息-冗余"`
TemplateId int `orm:"column(template_id);size(50)" description:"模板编号-冗余"`
SelfChecks string `orm:"column(self_checks);null" description:"自查内容"`
CheckTime time.Time `orm:"column(check_time);type(timestamp)" description:"机会筛选审核时间"`
CheckResultStatus int `orm:"column(check_result_status)" description:"机会筛选状态【1:待处理】【2:通过】【3:不通过】"`
SubmitCheckTime time.Time `orm:"column(submit_check_time);type(timestamp)" description:"提交筛选时间"`
SubmitCheckStatus int `orm:"column(submit_check_status)" description:"提交筛选状态 0:未提交 1:已提交"`
}
func (t *AuditFlowProcess) TableName() string {
... ... @@ -182,3 +182,23 @@ func UpdatetAuditFlowProcessToSubmit(o orm.Ormer, chanceId int64, level int, rev
}
return
}
//获取审核人最新的审核节点
func GetAuditorLatestAuditFlowProcess(chanceId int64, userId int64) (v *AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select * from audit_flow_process where chance_id=? and level>0 and uid=? order by id desc limit 1"
if err = utils.ExecuteQueryOneWithOrmer(o, &v, sql, chanceId, userId); err != nil {
return
}
return
}
//获取机会所有审核人
func GetChanceAllAuditors(chanceId int64) (v []*AuditFlowProcess, err error) {
o := orm.NewOrm()
sql := "select MAX(id) AS id,uid from audit_flow_process where chance_id=? and `level`>0 group by chance_id,uid"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
return
}
return
}
... ...
package models
import (
"fmt"
"opp/internal/utils"
"time"
"github.com/astaxie/beego/orm"
)
type ChanceCheckResult struct {
Id int64 `orm:"column(id);pk"`
ChanceId int64 `orm:"column(chance_id)"`
GroupId int64 `orm:"column(group_id);null"`
CheckPid int64 `orm:"column(check_pid)"`
CheckId int `orm:"column(check_id);null"`
CheckItem string `orm:"column(check_item);size(20);null" description:"检查项"`
Answer string `orm:"column(answer);size(50);null" description:"回答"`
Reason string `orm:"column(reason);size(200);null" description:"理由"`
UserCompanyId int64 `orm:"column(user_company_id);null"`
CreateAt time.Time `orm:"column(create_at);type(timestamp);null"`
}
func (t *ChanceCheckResult) TableName() string {
return "chance_check_result"
}
func init() {
orm.RegisterModel(new(ChanceCheckResult))
}
var (
SqlGetUserCheckResults = `select * from chance_check_result where chance_id =? and user_company_id=? order by group_id,check_id` //机会自查数据
)
// AddChanceCheckResult insert a new ChanceCheckResult into database and returns
// last inserted Id on success.
func AddChanceCheckResult(m *ChanceCheckResult) (id int64, err error) {
o := orm.NewOrm()
id, err = o.Insert(m)
return
}
// GetChanceCheckResultById retrieves ChanceCheckResult by Id. Returns error if
// Id doesn't exist
func GetChanceCheckResultById(id int64) (v *ChanceCheckResult, err error) {
o := orm.NewOrm()
v = &ChanceCheckResult{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
// UpdateChanceCheckResult updates ChanceCheckResult by Id and returns error if
// the record to be updated doesn't exist
func UpdateChanceCheckResultById(m *ChanceCheckResult) (err error) {
o := orm.NewOrm()
v := ChanceCheckResult{Id: m.Id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Update(m); err == nil {
fmt.Println("Number of records updated in database:", num)
}
}
return
}
// DeleteChanceCheckResult deletes ChanceCheckResult by Id and returns error if
// the record to be deleted doesn't exist
func DeleteChanceCheckResult(id int64) (err error) {
o := orm.NewOrm()
v := ChanceCheckResult{Id: id}
// ascertain id exists in the database
if err = o.Read(&v); err == nil {
var num int64
if num, err = o.Delete(&ChanceCheckResult{Id: id}); err == nil {
fmt.Println("Number of records deleted in database:", num)
}
}
return
}
//获取机会所有审核人
func GetCheckResultAllSubmitters(chanceId int64) (v []int64, err error) {
o := orm.NewOrm()
sql := "select DISTINCT user_company_id from chance_check_result where chance_id=?"
if err = utils.ExecuteQueryAllWithOrmer(o, &v, sql, chanceId); err != nil {
return
}
return
}
... ...
... ... @@ -59,7 +59,7 @@ type SelfCheck struct {
Answer string `json:"answer,omitempty"`
Reason string `json:"reason,omitempty"`
Id int64 `json:"Id"`
Id int64 `json:"id"`
ParentId int64 `json:"parentId"`
}
... ... @@ -168,14 +168,17 @@ func NewCheckQuestion(checkItem, title string, groupId int64, ops []CheckOption)
}
type CheckQuestion struct {
Id int64 `json:"-"`
ParentId int64 `json:"-"`
Id int64 `json:"id"`
ParentId int64 `json:"parentId"`
CheckItem string `json:"checkItem"`
Title string `json:"title"`
GroupId int64 `json:"groupId"`
Answer string `json:"answer,omitempty"`
Reason string `json:"reason,omitempty"`
CheckOptions []CheckOption `json:"options"`
Required bool `json:"required"` //是否必填
}
type CheckOption struct {
Item string `json:"item"`
... ... @@ -184,6 +187,7 @@ type CheckOption struct {
/*CheckQuestions 自查问题列表*/
type CheckQuestionsRequest struct {
Type int `json:"type"` //0.自查 1.筛选结果
ChanceId int64 `json:"chanceId" valid:"Required"`
}
type CheckQuestionsResponse struct {
... ... @@ -204,10 +208,19 @@ type SiftingPoolResponse struct {
/*筛选结果 SiftingResults */
type SiftingResultsRequest struct {
PageInfo
Uid int64 `json:"uid"` //注入用户 测试使用
//SubmitStatus int `json:"submitStatus"` //0:待我提交 1:提交
SiftedStatus int `json:"siftedStatus"` //筛选状态 1:待处理 2:通过 3:不通过
Uid int64 `json:"uid"` //注入用户 测试使用
SiftedStatus int `json:"siftingStatus"` //筛选状态 1:待处理 2:通过 3:不通过
}
type SiftingResultsResponse struct {
ChancePoolResponse
}
/*SubmitChecks 提交自查*/
type SubmitChecksRequest struct {
//Type int `json:"type"` //1.审核人
Uid int64 `json:"uid"`
ChanceId int64 `json:"chanceId" valid:"Required"`
SelfChecks SelfChecks `json:"selfChecks"`
}
type SubmitChecksResponse struct {
}
... ...
... ... @@ -289,6 +289,14 @@ func init() {
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SubmitChecks",
Router: `/submitSiftingResult`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"],
beego.ControllerComments{
Method: "SympathyAction",
Router: `/sympathyAction`,
AllowHTTPMethods: []string{"post"},
... ...
... ... @@ -281,6 +281,7 @@ func GetCheckQuestionsByTemplateId(id int64) (rsp []*protocol.CheckQuestion, err
rsp = append(rsp, item)
idx++
}
setQuestionRequire(rsp)
return
}
... ... @@ -302,17 +303,13 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp
if len(chance.SelfChecks) == 0 {
return
}
if chance.ReviewStatus == protocol.ReviewStatusPass {
log.Warn("机会已审核通过不可编辑自查数据:", chance.Id)
return
}
if e := json.Unmarshal([]byte(chance.SelfChecks), &selfChecks); e != nil {
log.Error(e)
return
}
var tmpGroupId int64
var idx int = 0
var groupIdx = 0
var idx int = 0 //组内排序
var groupIdx = 0 //分组序号
for i := range selfChecks {
c := selfChecks[i]
if tmpGroupId != c.GroupId {
... ... @@ -328,26 +325,91 @@ func GetCheckQuestionsByChanceId(header *protocol.RequestHeader, id int64) (rsp
}
}
if item.Id == 0 {
item.Id, item.ParentId = genCustomizeQuestionId(idx, groupIdx)
item.Id, item.ParentId = genCustomizeQuestionId(i, idx, tmpGroupId)
}
rsp = append(rsp, item)
idx++
}
setQuestionRequire(rsp)
return
}
//从问题筛选结果获取已回答的问题
func GetCheckQuestionsByChanceCheckResult(header *protocol.RequestHeader, id int64) (rsp []*protocol.CheckQuestion, err error) {
var (
checks []*models.ChanceCheckResult
groupIdx int = 1 //分组序号
)
if err = utils.ExecuteQueryAll(&checks, models.SqlGetUserCheckResults, id, header.UserId); err != nil {
if err == orm.ErrNoRows {
return
}
log.Error(err)
return
}
for i := range checks {
c := checks[i]
item := &protocol.CheckQuestion{
Id: int64(c.CheckId),
ParentId: int64(c.CheckPid),
GroupId: int64(c.GroupId),
CheckItem: c.CheckItem,
Answer: c.Answer,
Reason: c.Reason,
CheckOptions: protocol.CheckOptionsApprove,
}
if c.CheckPid == 0 {
item.Title = fmt.Sprintf("%v、%v", groupIdx, c.CheckItem)
}
rsp = append(rsp, item)
}
setQuestionRequire(rsp)
return
}
//设置问题需要填写
func setQuestionRequire(list []*protocol.CheckQuestion) {
if len(list) == 0 {
return
}
var gIdx = -1
for i := 0; i < len(list); i++ {
if gIdx < 0 || list[gIdx].GroupId != list[i].GroupId {
gIdx = i
} else {
continue
}
hasSub := false
for j := i + 1; j < len(list); j++ {
if list[i].GroupId == list[j].GroupId {
if !hasSub {
hasSub = true
}
} else {
break
}
}
//只有一级维度的必须填写
if !hasSub {
list[gIdx].Required = true
}
}
}
func getQuestionTitle(groupIdx int, idx int, title string) string {
if idx == 0 {
return fmt.Sprintf("%v、%v", groupIdx, title)
return fmt.Sprintf("%v、%v", groupIdx, title)
}
return fmt.Sprintf("%v.%v、%v", groupIdx, idx, title)
return fmt.Sprintf("%v.%v、%v", groupIdx, idx, title)
}
//自定义id
//@return id:问题序号 parentId:父级id
func genCustomizeQuestionId(idx, groupId int) (id int64, parentId int64) {
id = int64(idx) + 1
func genCustomizeQuestionId(seq int, idx int, groupId int64) (id int64, parentId int64) {
id = int64(seq) + 1
//同一分组的第一个 是一级
if idx == 0 {
//id = groupId
parentId = 0
return
}
... ...
... ... @@ -2216,69 +2216,26 @@ func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.Chance
func CheckQuestions(header *protocol.RequestHeader, request *protocol.CheckQuestionsRequest) (rsp *protocol.CheckQuestionsResponse, err error) {
var ()
rsp = &protocol.CheckQuestionsResponse{}
rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId)
if err != nil {
log.Error(err)
}
return
}
//SiftingPool 筛选池
func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRequest) (rsp *protocol.SiftingPoolResponse, err error) {
var (
ormItems []protocol.ChanceSiftItemOrm
)
rsp = &protocol.SiftingPoolResponse{}
rsp.List = make([]protocol.CommonListItem, 0)
//测试使用
if request.Uid != 0 {
header.UserId = request.Uid
}
if rsp.Total, err = models.GetSiftingChance(header.UserId, request.SubmitStatus, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
switch request.Type {
case 0: //自查问题列表
rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId)
if err != nil {
log.Error(err)
return
}
log.Error(err)
return
}
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
commItem.Chance.CreateTime = ormItem.ChanceApproveTime.Unix() * 1000
if request.SubmitStatus == protocol.Submited {
commItem.Chance.CreateTime = ormItem.SubmitCheckTime.Unix() * 1000
}
rsp.List = append(rsp.List, commItem)
}
return
}
//筛选结果
func SiftingResults(header *protocol.RequestHeader, request *protocol.SiftingResultsRequest) (rsp *protocol.SiftingResultsResponse, err error) {
var (
ormItems []protocol.ChanceSiftResultOrm
)
rsp = &protocol.SiftingResultsResponse{}
rsp.List = make([]protocol.CommonListItem, 0)
//测试使用
if request.Uid != 0 {
header.UserId = request.Uid
}
if rsp.Total, err = models.GetSiftingResults(header.UserId, protocol.Submited, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
case 1: //筛选结果问题列表
rsp.Questions, err = agg.GetCheckQuestionsByChanceCheckResult(header, request.ChanceId)
if err == orm.ErrNoRows || len(rsp.Questions) == 0 {
rsp.Questions, err = agg.GetCheckQuestionsByChanceId(header, request.ChanceId)
if err != nil {
log.Error(err)
return
}
err = nil
return
}
log.Error(err)
return
}
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
commItem.Chance.CreateTime = ormItem.CheckTime.Unix() * 1000
rsp.List = append(rsp.List, commItem)
for i := range rsp.Questions {
rsp.Questions[i].CheckOptions = protocol.CheckOptionsApprove
}
}
return
}
... ...
package chance
import (
"github.com/astaxie/beego/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/utils"
"opp/models"
"opp/protocol"
"opp/services/agg"
"time"
)
//SiftingPool 筛选池
func SiftingPool(header *protocol.RequestHeader, request *protocol.SiftingPoolRequest) (rsp *protocol.SiftingPoolResponse, err error) {
var (
ormItems []protocol.ChanceSiftItemOrm
)
rsp = &protocol.SiftingPoolResponse{}
rsp.List = make([]protocol.CommonListItem, 0)
//测试使用
if request.Uid != 0 {
header.UserId = request.Uid
}
if rsp.Total, err = models.GetSiftingChance(header.UserId, request.SubmitStatus, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
commItem.Chance.CreateTime = ormItem.ChanceApproveTime.Unix() * 1000
if request.SubmitStatus == protocol.Submited {
commItem.Chance.CreateTime = ormItem.SubmitCheckTime.Unix() * 1000
}
rsp.List = append(rsp.List, commItem)
}
return
}
//筛选结果
func SiftingResults(header *protocol.RequestHeader, request *protocol.SiftingResultsRequest) (rsp *protocol.SiftingResultsResponse, err error) {
var (
ormItems []protocol.ChanceSiftResultOrm
)
rsp = &protocol.SiftingResultsResponse{}
rsp.List = make([]protocol.CommonListItem, 0)
//测试使用
if request.Uid != 0 {
header.UserId = request.Uid
}
if rsp.Total, err = models.GetSiftingResults(header.UserId, protocol.Submited, request.SiftedStatus, request.Offset(), request.PageSize, &ormItems); err != nil {
if err == orm.ErrNoRows {
err = nil
return
}
log.Error(err)
return
}
for i := 0; i < len(ormItems); i++ {
ormItem := ormItems[i]
commItem := agg.NewCommonListItem(header, ormItem.CommChanceItemOrm)
commItem.Chance.CreateTime = ormItem.CheckTime.Unix() * 1000
rsp.List = append(rsp.List, commItem)
}
return
}
//提交自查
func SubmitChecks(header *protocol.RequestHeader, request *protocol.SubmitChecksRequest) (rsp *protocol.SubmitChecksResponse, err error) {
var (
p *models.AuditFlowProcess
)
//测试
if request.Uid != 0 {
header.UserId = request.Uid
}
if p, err = models.GetAuditorLatestAuditFlowProcess(request.ChanceId, header.UserId); err != nil {
log.Error(request.ChanceId, header.UserId, err)
if err == orm.ErrNoRows {
err = nil
}
return
}
rsp = &protocol.SubmitChecksResponse{}
o := orm.NewOrm()
o.Begin()
var (
DeleteAll = `delete from chance_check_result where chance_id =? and user_company_id=? `
UpdateCommitStatus = `update audit_flow_process set submit_check_status=? ,submit_check_time=now() where chance_id=? and id=?`
UpdateChanceCheckResultStatus = `update chance set check_result_status=? where id=? and (check_result_status=? or check_result_status is null)`
)
if err = utils.ExecuteSQLWithOrmer(o, DeleteAll, request.ChanceId, header.UserId); err != nil {
log.Error(err)
o.Rollback()
return
}
var groupIdx = -1
for i := range request.SelfChecks {
c := request.SelfChecks[i]
m := NewChanceCheckResult(c, request.ChanceId, header.UserId)
if groupIdx == -1 || request.SelfChecks[groupIdx].GroupId != request.SelfChecks[i].GroupId {
groupIdx = i
}
if c.Id == 0 {
m.CheckId = i + 1
m.CheckPid = int64(groupIdx + 1)
if groupIdx == i {
m.CheckPid = 0
}
} else {
m.CheckId = int(c.Id)
m.CheckPid = int64(c.ParentId)
}
if _, err = o.Insert(m); err != nil {
log.Error(err)
o.Rollback()
return
}
}
//更新审核人提交状态
if p.SubmitCheckStatus == protocol.Submiting {
//更新
if err = utils.ExecuteSQLWithOrmer(o, UpdateCommitStatus, protocol.Submited, request.ChanceId, p.Id); err != nil {
log.Error(err)
o.Rollback()
return
}
//插入一条数据
}
//更新机会筛选状态
if _, result := CheckIsCommitAllCheck(request.ChanceId); result {
if err = utils.ExecuteSQLWithOrmer(o, UpdateChanceCheckResultStatus, protocol.Waiting, request.ChanceId, protocol.None); err != nil {
log.Error(err)
o.Rollback()
return
}
}
o.Commit()
return
}
func NewChanceCheckResult(c protocol.SelfCheck, chanceId int64, uid int64) *models.ChanceCheckResult {
return &models.ChanceCheckResult{
Id: idgen.Next(),
ChanceId: chanceId,
GroupId: c.GroupId,
CheckItem: c.CheckItem,
Answer: c.Answer,
Reason: c.Reason,
UserCompanyId: uid,
CreateAt: time.Now(),
}
}
//判断审核人筛选结果是否都已提交
func CheckIsCommitAllCheck(chanceId int64) (err error, result bool) {
var (
audits []*models.AuditFlowProcess
submiters []int64
)
result = false
if audits, err = models.GetChanceAllAuditors(chanceId); err != nil {
log.Error(err)
return
}
if submiters, err = models.GetCheckResultAllSubmitters(chanceId); err != nil {
log.Error(err)
return
}
if len(audits) == len(submiters) {
result = true
}
return
}
... ...