作者 tangxvhui

自查内容筛选结果

... ... @@ -167,4 +167,48 @@ func (c *AuditController) GetChanceReviseLog() {
return
}
// GetChanceReviseLog
//GetChanceCheckResultList 获取机会的自查内容的筛选结果列表
//@router /v1/audit/check_result/list
func (c *AuditController) GetChanceCheckResultList() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
protocol.RequestPageInfo
CheckResultStatus int8 `json:"check_result_status"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
companyId := c.GetCompanyId()
rspData := serveaudit.GetChanceCheckResultList(param.PageIndex, param.PageSize, companyId, param.CheckResultStatus)
msg = protocol.NewReturnResponse(rspData, nil)
return
}
//GetChanceCheckResultInfo 获取机会的自查内容的筛选结果详情
//@router /v1/audit/check_result/info
func (c *AuditController) GetChanceCheckResultInfo() {
// var msg *protocol.ResponseMessage
// defer func() {
// c.ResposeJson(msg)
// }()
// type Parameter struct {
// protocol.RequestPageInfo
// CheckResultStatus int8 `json:"check_result_status"`
// }
// var param Parameter
// if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
// log.Error("json 解析失败", err)
// msg = protocol.BadRequestParam("1")
// return
// }
// companyId := c.GetCompanyId()
// rspData := serveaudit.GetChanceCheckResultList(param.PageIndex, param.PageSize, companyId, param.CheckResultStatus)
// msg = protocol.NewReturnResponse(rspData, nil)
return
}
... ...
... ... @@ -35,6 +35,8 @@ type Chance struct {
Code string `orm:"column(code)" description:"机会编码"`
Status int8 `orm:"column(status)" description:"机会状态 1:开启 2:关闭"`
SelfChecks string `orm:"column(self_checks)" description:"自查内容"`
CheckResultStatus int8 ` orm:"column(check_result_status)"`
CheckTime time.Time `orm:"column(check_time);type(timestamp);"`
}
func (t *Chance) TableName() string {
... ... @@ -95,6 +97,19 @@ var ChanceStatusMap = map[int8]string{
ChanceStatusForbid: "已关闭",
}
//机会自查内容筛选状态 【1:待处理未设置】【2:通过】【3:不通过】
const (
CheckResultStatusWait int8 = 1
CheckResultStatusPass int8 = 2
CheckResultStatusNOPass int8 = 3
)
var CheckResultStatusMap = map[int8]string{
CheckResultStatusWait: "未设置",
CheckResultStatusPass: "通过",
CheckResultStatusNOPass: "未通过",
}
//ChanceSelfCheck chance表中SelfChecks字段的json结构
type ChanceSelfCheck struct {
ChickItem string `json:"checkItem"`
... ...
package models
import (
"time"
"github.com/astaxie/beego/orm"
)
type ChanceCheckResult struct {
Id int `orm:"column(id);pk"`
ChanceId int64 `orm:"column(chance_id)"`
GroupId int64 `orm:"column(group_id);null"`
Pid int64 `orm:"column(pid)"`
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))
}
// GetChanceCheckResultById retrieves ChanceCheckResult by Id. Returns error if
// Id doesn't exist
func GetChanceCheckResultById(id int) (v *ChanceCheckResult, err error) {
o := orm.NewOrm()
v = &ChanceCheckResult{Id: id}
if err = o.Read(v); err == nil {
return v, nil
}
return nil, err
}
func GetChanceCheckResultByChancce(chanceId int64) ([]ChanceCheckResult, error) {
var (
err error
data []ChanceCheckResult
)
o := orm.NewOrm()
_, err = o.QueryTable(&ChanceCheckResult{}).
Filter("chance_id", chanceId).
All(&data)
return data, err
}
... ...
... ... @@ -293,3 +293,41 @@ type ChanceFlowLog struct {
NickName string `json:"nick_name" orm:"column(nick_name)"`
Code int `json:"code" orm:"column(code)"`
}
//ReponseChanceCheckResult 响应筛选结果详情
type ReponseChanceCheckResult struct {
CustomItem []string `json:"custom_item"`
CheckData []ChanceCheckResultData `json:"check_data"`
}
// ChanceCheckResultData 筛选结果详情数据
type ChanceCheckResultData struct {
Total string `json:"total"`
CheckItem string `json:"check_item"`
CustomItemData map[string]string `json:"custom_item_data"`
}
//ResponseChanceCheckResultList 响应自查内容筛选结果列表
type ResponseChanceCheckResultList struct {
ResponsePageInfo
List []RspCheckResultList `json:"lists"`
}
type RspCheckResultList struct {
Id string `json:"id"` //机会的id
Code string `json:"code" `
ChanceType string `json:"chance_type"` //一级分类
TemplateName string `json:"template_name"` //二级分类
UserName string `json:"user_name"` // 提交人
Department string `json:"department"` //提交部门
CreateTime string `json:"create_time"` //提交时间
PublishStatus int `json:"publish_status"` //公开状态
PublishStatusName string `json:"publish_status_name"` //
ReviewStatus int8 `json:"review_status"` //审批状态
ReviewStatusName string `json:"review_status_name"`
Status int8 `json:"status"` //开启、关闭状态
StatusName string `json:"status_name"`
DiscoveryScore string `json:"discovery_score"`
CommentTotal string `json:"comment_total"`
CheckResultStatusName string `json:"check_result_status_name"` //自查内容筛选状态
}
... ...
... ... @@ -107,6 +107,7 @@ func init() {
beego.NSRouter("/info", &controllers.AuditController{}, "post:AuditInfo"),
beego.NSRouter("/allow_forbid", &controllers.AuditController{}, "post:AllowForbidAudit"),
beego.NSRouter("/revise/info", &controllers.AuditController{}, "post:GetChanceReviseLog"),
beego.NSRouter("/check_result/list", &controllers.AuditController{}, "post:GetChanceCheckResultList"),
),
beego.NSNamespace("/rank",
beego.NSRouter("/type/list", &controllers.RankController{}, "post:GetRankType"),
... ...
... ... @@ -14,22 +14,6 @@ import (
"time"
)
type SqlData struct {
Id int64 `orm:"column(id)"`
UserId int64 `orm:"column(user_id)"`
NickName string `orm:"column(nick_name)"`
DepartmentId int64 `orm:"column(department_id)"`
AuditTemplateId int64 `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
PublishStatus int `orm:"column(publish_status)"`
CreateAt string `orm:"column(create_at)"`
ReviewStatus int8 `orm:"column(review_status)"`
Status int8 `orm:"column(status)"`
DiscoveryScore string `orm:"column(discovery_score)"`
CommentTotal string `orm:"column(comment_total)"`
Code string `orm:"column(code)"`
}
func getAuditUserHasPermission(userid int64, usercompanyid int64) (
serverabc.PermissionOptionObject, error) {
var permissionObject serverabc.PermissionOptionObject
... ... @@ -155,7 +139,21 @@ func buildSqlForAuditList(usercompanyid int64, companyid int64, userid int64) st
}
func GetAuditList(param protocol.RequestAuditList, companyid int64, userid int64) (protocol.ResponseAuditList, error) {
type SqlData struct {
Id int64 `orm:"column(id)"`
UserId int64 `orm:"column(user_id)"`
NickName string `orm:"column(nick_name)"`
DepartmentId int64 `orm:"column(department_id)"`
AuditTemplateId int64 `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
PublishStatus int `orm:"column(publish_status)"`
CreateAt string `orm:"column(create_at)"`
ReviewStatus int8 `orm:"column(review_status)"`
Status int8 `orm:"column(status)"`
DiscoveryScore string `orm:"column(discovery_score)"`
CommentTotal string `orm:"column(comment_total)"`
Code string `orm:"column(code)"`
}
var (
datasql = strings.Builder{}
countsql = strings.Builder{}
... ...
package audit
import (
"fmt"
"oppmg/common/log"
"oppmg/models"
"oppmg/protocol"
"oppmg/utils"
)
//GetChanceCheckResultInfo 获取机会详情
func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.ReponseChanceCheckResult, error) {
var (
chanceData *models.Chance
err error
)
rsp := protocol.ReponseChanceCheckResult{
CustomItem: []string{},
CheckData: []protocol.ChanceCheckResultData{},
}
chanceData, err = models.GetChanceById(chanceId)
if err != nil {
log.Error("获取机会数据失败,err:%s", err)
return rsp, protocol.NewErrWithMessage("1")
}
if chanceData.CompanyId != companyid {
log.Error("机会的公司数据无法对应")
return rsp, protocol.NewErrWithMessage("1")
}
if chanceData.CheckResultStatus < models.CheckResultStatusWait {
log.Error("机会的自查内容筛选状态错误")
return rsp, protocol.NewErrWithMessage("1")
}
var (
checkResultData []models.ChanceCheckResult
)
checkResultData, err = models.GetChanceCheckResultByChancce(chanceId)
if err != nil {
log.Error("未获得指定的机会自查内容筛选结果,err;%s", err)
return rsp, nil
}
//组装响应数据
//定义动态数据列
customItems := utils.NewArraySetString()
//自查内容项
checkItems := utils.NewArraySetString()
_ = checkResultData
_ = customItems
_ = checkItems
return rsp, err
}
func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, checkResultStatus int8) protocol.ResponseChanceCheckResultList {
type SqlData struct {
Id int64 `orm:"column(id)"`
UserId int64 `orm:"column(user_id)"`
NickName string `orm:"column(nick_name)"`
DepartmentId int64 `orm:"column(department_id)"`
AuditTemplateId int64 `orm:"column(audit_template_id)"`
ChanceTypeId int `orm:"column(chance_type_id)"`
PublishStatus int `orm:"column(publish_status)"`
CreateAt string `orm:"column(create_at)"`
ReviewStatus int8 `orm:"column(review_status)"`
Status int8 `orm:"column(status)"`
DiscoveryScore string `orm:"column(discovery_score)"`
CommentTotal string `orm:"column(comment_total)"`
Code string `orm:"column(code)"`
CheckResultStatus int8 `orm:"column(check_result_status)"`
}
returnData := protocol.ResponseChanceCheckResultList{
ResponsePageInfo: protocol.ResponsePageInfo{
TotalPage: 0,
CurrentPage: pageIndex,
},
List: make([]protocol.RspCheckResultList, 0),
}
datasql := `SELECT a.id,a.department_id,a.audit_template_id,a.chance_type_id
,a.publish_status,a.create_at,a.review_status,a.status,a.check_result_status
,a.discovery_score,a.comment_total ,a.code,d.nick_name,d.id as user_id
FROM chance AS a
LEFt JOIN user_company AS c ON c.id = a.user_id
LEFt JOIN user AS d ON c.user_id = d.id
where a.company_id=? `
countsql := ` SELECT count(*) FROM chance as a
where a.company_id=? `
cond := []interface{}{companyId}
if checkResultStatus > 0 {
datasql += ` AND a.check_result_status=? `
countsql += ` AND a.check_result_status=? `
cond = append(cond, checkResultStatus)
} else {
datasql += ` AND a.check_result_status>0 `
countsql += ` AND a.check_result_status>0 `
}
dataStart := (pageIndex - 1) * pageSize
datasql += fmt.Sprintf(` ORDER BY a.create_at DESC limit %d,%d `, dataStart, pageSize)
var (
cnt int
sqldata []SqlData
err error
)
err = utils.ExecuteQueryOne(&cnt, countsql, cond...)
if err != nil {
log.Error("EXCUTE SQL ERR:%s", err)
return returnData
}
if cnt <= 0 {
return returnData
}
err = utils.ExecuteQueryAll(&sqldata, datasql, cond...)
if err != nil {
log.Error("EXCUTE SQL ERR:%s", err)
return returnData
}
for _, v := range sqldata {
item := protocol.RspCheckResultList{
Id: fmt.Sprint(v.Id),
Status: v.Status,
StatusName: models.ChanceStatusMap[v.Status],
PublishStatus: v.PublishStatus,
PublishStatusName: models.ChancePublishStatusMap[v.PublishStatus],
ReviewStatus: v.ReviewStatus,
ReviewStatusName: models.ChanceReviewStatusMap[v.ReviewStatus],
Code: v.Code,
DiscoveryScore: v.DiscoveryScore,
CommentTotal: v.CommentTotal,
UserName: v.NickName,
CreateTime: v.CreateAt,
CheckResultStatusName: models.CheckResultStatusMap[v.CheckResultStatus],
}
if d, err := models.GetDepartmentById(v.DepartmentId); err == nil {
item.Department = d.Name
}
if ct, err := models.GetChanceTypeById(v.ChanceTypeId); err == nil {
item.ChanceType = ct.Name
}
if tp, err := models.GetAuditTemplateById(v.AuditTemplateId); err == nil {
item.TemplateName = tp.Name
}
returnData.List = append(returnData.List, item)
}
returnData.TotalPage = cnt
returnData.CurrentPage = pageIndex
return returnData
}
... ...
... ... @@ -75,3 +75,49 @@ func ArrayInt64Unique(s []int64) []int64 {
}
return newS
}
//ArraySetString 构建元素不重复的数组
//可按需扩展
type ArraySetString struct {
m map[string]int
}
func NewArraySetString() ArraySetString {
return ArraySetString{
m: make(map[string]int),
}
}
func (set *ArraySetString) Has(str string) bool {
if _, ok := set.m[str]; ok {
return true
}
return false
}
//Add 追加元素
func (set *ArraySetString) Add(str string) {
if _, ok := set.m[str]; ok {
return
}
l := len(set.m)
set.m[str] = l
}
//Remove 移除指定元素
func (set *ArraySetString) Remove(str string) {
delete(set.m, str)
}
//Len 元素长度
func (set *ArraySetString) Len() int {
return len(set.m)
}
//ToSlice 转换为切片输出
func (set *ArraySetString) ToSlice() []string {
newSlice := make([]string, len(set.m))
for k, v := range set.m {
newSlice[v] = k
}
return newSlice
}
... ...