作者 tangxvhui

添加 自查内容 筛选功能

... ... @@ -186,29 +186,59 @@ func (c *AuditController) GetChanceCheckResultList() {
}
companyId := c.GetCompanyId()
rspData := serveaudit.GetChanceCheckResultList(param.PageIndex, param.PageSize, companyId, param.CheckResultStatus)
msg = protocol.NewReturnResponse(rspData, nil)
msg = protocol.NewPageDataResponse(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)
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
ChanceId string `json:"chance_id"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
chanceId, _ := strconv.ParseInt(param.ChanceId, 10, 64)
companyId := c.GetCompanyId()
rspData, err := serveaudit.GetChanceCheckResultInfo(chanceId, companyId)
msg = protocol.NewReturnResponse(rspData, err)
return
}
//GetChanceCheckResultInfo 获取机会的自查内容的筛选结果详情
//@router /v1/audit/check_result/pass_or_no
func (c *AuditController) ChanceCheckResultPassOrNo() {
var msg *protocol.ResponseMessage
defer func() {
c.ResposeJson(msg)
}()
type Parameter struct {
ChanceId string `json:"chance_id"`
Status int `json:"status"`
}
var param Parameter
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
log.Error("json 解析失败", err)
msg = protocol.BadRequestParam("1")
return
}
chanceId, _ := strconv.ParseInt(param.ChanceId, 10, 64)
companyId := c.GetCompanyId()
var err error
switch param.Status {
case 1:
err = serveaudit.ChanceCheckResultPass(chanceId, companyId)
case 2:
err = serveaudit.ChanceCheckResultNoPass(chanceId, companyId)
}
msg = protocol.NewReturnResponse(nil, err)
return
}
... ...
... ... @@ -108,6 +108,8 @@ func init() {
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.NSRouter("/check_result/info", &controllers.AuditController{}, "post:GetChanceCheckResultInfo"),
beego.NSRouter("/check_result/pass_or_no", &controllers.AuditController{}, "post:ChanceCheckResultPassOrNo"),
),
beego.NSNamespace("/rank",
beego.NSRouter("/type/list", &controllers.RankController{}, "post:GetRankType"),
... ...
... ... @@ -8,7 +8,7 @@ import (
"oppmg/utils"
)
//GetChanceCheckResultInfo 获取机会详情
//GetChanceCheckResultInfo 获取机会自查内容筛选详情
func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.ReponseChanceCheckResult, error) {
var (
chanceData *models.Chance
... ... @@ -31,23 +31,82 @@ func GetChanceCheckResultInfo(chanceId int64, companyid int64) (protocol.Reponse
log.Error("机会的自查内容筛选状态错误")
return rsp, protocol.NewErrWithMessage("1")
}
rsp, err = getChanceCheckResultData(chanceId)
return rsp, err
}
//getChanceCheckResultData 机会自查内容筛选详情数据输出
func getChanceCheckResultData(chanceId int64) (protocol.ReponseChanceCheckResult, error) {
var (
checkResultData []models.ChanceCheckResult
err error
)
rsp := protocol.ReponseChanceCheckResult{}
checkResultData, err = models.GetChanceCheckResultByChancce(chanceId)
if err != nil {
log.Error("未获得指定的机会自查内容筛选结果,err;%s", err)
return rsp, nil
}
//组装响应数据
//定义动态数据列
customItems := utils.NewArraySetString()
//自查内容中的用户id
userIds := utils.NewArraySetInt64()
//自查内容项
checkItems := utils.NewArraySetString()
_ = checkResultData
_ = customItems
_ = checkItems
return rsp, err
checkResultMap := make(map[string]*protocol.ChanceCheckResultData)
for _, v := range checkResultData {
userIds.Add(v.UserCompanyId)
checkItems.Add(v.CheckItem)
if _, ok := checkResultMap[v.CheckItem]; ok {
checkResultMap[v.CheckItem].CustomItemData[fmt.Sprint(v.UserCompanyId)] = v.Answer
continue
}
userAnswer := map[string]string{
fmt.Sprint(v.UserCompanyId): v.Answer,
}
checkResultMap[v.CheckItem] = &protocol.ChanceCheckResultData{
CheckItem: v.CheckItem,
CustomItemData: userAnswer,
}
}
usernameMap := make(map[string]string)
for _, v := range userIds.ToSlice() {
idString := fmt.Sprint(v)
u, err := models.GetUserCompanyById(v)
if err == nil {
usernameMap[idString] = u.NickName
} else {
usernameMap[idString] = idString
}
rsp.CustomItem = append(rsp.CustomItem, usernameMap[idString])
}
for _, v := range checkItems.ToSlice() {
newCustomItemData := map[string]string{}
for kk, vv := range usernameMap {
if answer, ok := checkResultMap[v].CustomItemData[kk]; ok {
newCustomItemData[vv] = answer
} else {
newCustomItemData[vv] = ""
}
}
answerYes := 0 //回答:是
answerNo := 0 //回答:否
answerAny := 0 //回答:不清楚
checkResultMap[v].CustomItemData = newCustomItemData
for _, answerData := range checkResultMap[v].CustomItemData {
switch answerData {
case "是":
answerYes++
case "否":
answerNo++
case "不清楚":
answerAny++
}
}
checkResultMap[v].Total = fmt.Sprintf("是:%d 否:%d 不清楚:%d", answerYes, answerNo, answerAny)
rsp.CheckData = append(rsp.CheckData, *checkResultMap[v])
}
return rsp, nil
}
func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, checkResultStatus int8) protocol.ResponseChanceCheckResultList {
... ... @@ -145,3 +204,47 @@ func GetChanceCheckResultList(pageIndex int, pageSize int, companyId int64, chec
returnData.CurrentPage = pageIndex
return returnData
}
func ChanceCheckResultPass(chanceId int64, companyId int64) error {
var (
err error
chanceData *models.Chance
)
chanceData, err = models.GetChanceById(chanceId)
if err != nil {
log.Error("未找到指定机会id=%d,err:%s", chanceId, err)
return protocol.NewErrWithMessage("1")
}
if chanceData.CompanyId != companyId {
log.Error("机会对应的公司不匹配")
return protocol.NewErrWithMessage("1")
}
chanceData.CheckResultStatus = models.CheckResultStatusPass
err = models.UpdateChanceById(chanceData, []string{"CheckResultStatus"})
if err != nil {
log.Error("更新chance数据失败,err;%s", err)
}
return nil
}
func ChanceCheckResultNoPass(chanceId int64, companyId int64) error {
var (
err error
chanceData *models.Chance
)
chanceData, err = models.GetChanceById(chanceId)
if err != nil {
log.Error("未找到指定机会id=%d,err:%s", chanceId, err)
return protocol.NewErrWithMessage("1")
}
if chanceData.CompanyId != companyId {
log.Error("机会对应的公司不匹配")
return protocol.NewErrWithMessage("1")
}
chanceData.CheckResultStatus = models.CheckResultStatusNOPass
err = models.UpdateChanceById(chanceData, []string{"CheckResultStatus"})
if err != nil {
log.Error("更新chance数据失败,err;%s", err)
}
return nil
}
... ...
... ... @@ -121,3 +121,49 @@ func (set *ArraySetString) ToSlice() []string {
}
return newSlice
}
//ArraySetString 构建元素不重复的数组
//可按需扩展
type ArraySetInt64 struct {
m map[int64]int
}
func NewArraySetInt64() ArraySetInt64 {
return ArraySetInt64{
m: make(map[int64]int),
}
}
func (set *ArraySetInt64) Has(str int64) bool {
if _, ok := set.m[str]; ok {
return true
}
return false
}
//Add 追加元素
func (set *ArraySetInt64) Add(str int64) {
if _, ok := set.m[str]; ok {
return
}
l := len(set.m)
set.m[str] = l
}
//Remove 移除指定元素
func (set *ArraySetInt64) Remove(str int64) {
delete(set.m, str)
}
//Len 元素长度
func (set *ArraySetInt64) Len() int {
return len(set.m)
}
//ToSlice 转换为切片输出
func (set *ArraySetInt64) ToSlice() []int64 {
newSlice := make([]int64, len(set.m))
for k, v := range set.m {
newSlice[v] = k
}
return newSlice
}
... ...