作者 tangxvhui

bug 修复

... ... @@ -99,8 +99,9 @@ var ChanceStatusMap = map[int8]string{
ChanceStatusForbid: "已关闭",
}
//机会自查内容筛选状态 【1:待处理未设置】【2:通过】【3:不通过】
//机会自查内容筛选状态 【0:未提交】【1:待处理未设置】【2:通过】【3:不通过】
const (
CheckResultStatusNone int8 = 0
CheckResultStatusWait int8 = 1
CheckResultStatusPass int8 = 2
CheckResultStatusNOPass int8 = 3
... ... @@ -124,27 +125,96 @@ type ChanceSelfCheckData struct {
func (m *Chance) GetSelfCheckData() []ChanceSelfCheckData {
var data []ChanceSelfCheckData
if m.CheckResultStatus > CheckResultStatusWait {
var temp []ChanceSelfCheckData
json.Unmarshal([]byte(m.CheckResult), &temp)
//只要一级的数据
for i := range temp {
if temp[i].ParentId > 0 {
json.Unmarshal([]byte(m.CheckResult), &data)
return data
}
func (m *Chance) GetCheckResultData() []ChanceSelfCheckData {
var data []ChanceSelfCheckData
json.Unmarshal([]byte(m.CheckResult), &data)
return data
}
type ChanceSelfCheckList []ChanceSelfCheckData
func (s ChanceSelfCheckList) Format() ChanceSelfCheckList {
if len(s) == 0 {
return s
}
for i := range s {
if strings.TrimSpace(s[i].Answer) == "否" {
s[i].Reason = strings.TrimSpace(s[i].Reason)
}
}
return s
}
func (s ChanceSelfCheckList) SetSelfChecksLevel1ByRule() (err error) {
if len(s) == 0 {
return
}
s.Format()
var gIdx = -1
for i := 0; i < len(s); i++ {
if gIdx < 0 || s[gIdx].GroupId != s[i].GroupId {
gIdx = i
} else {
continue
}
data = append(data, temp[i])
hasSub := false
var (
cntYes = 0 //是
cntNo = 0 //否
cntUncertain = 0 //不确定
)
for j := i + 1; j < len(s); j++ {
if s[i].GroupId == s[j].GroupId {
if !hasSub {
hasSub = true
}
} else {
json.Unmarshal([]byte(m.SelfChecks), &data)
for i := range data {
reason := strings.TrimSpace(data[i].Reason)
if data[i].Answer == "否" && len(reason) > 0 {
data[i].Answer = fmt.Sprintf("否,理由:%s", data[i].Reason)
break
}
answer := s[j].Answer
if strings.EqualFold(strings.TrimSpace(answer), "是") {
cntYes++
} else if strings.EqualFold(strings.TrimSpace(answer), "否") {
cntNo++
} else if strings.EqualFold(strings.TrimSpace(answer), "不清楚") {
cntUncertain++
}
}
//只有一级维度的必须填写
if hasSub {
if cntYes > 0 {
s[gIdx].Answer = "是"
} else if cntNo > 0 {
s[gIdx].Answer = "否"
} else if cntUncertain > 0 {
s[gIdx].Answer = "不清楚"
}
}
if hasSub && cntYes == 0 && cntNo == 0 && cntUncertain == 0 {
err = fmt.Errorf("未填写自查项:%v,二级维度至少需要填写一项", s[gIdx].CheckItem)
}
if !hasSub && len(s[gIdx].Answer) == 0 {
err = fmt.Errorf("未填写自查项:%v", s[gIdx].CheckItem)
}
}
return
}
return data
//格式化数据结构
func (s ChanceSelfCheckList) ClearEmpty() (rsp ChanceSelfCheckList) {
if len(s) == 0 {
return
}
for i := range s {
if len(s[i].Answer) > 0 {
rsp = append(rsp, s[i])
}
}
return
}
// AddChance insert a new Chance into database and returns
... ...
... ... @@ -443,19 +443,35 @@ func getAuditFlowLog(chanceid int64) ([]protocol.ChanceFlowLog, error) {
}
func getChanceSelfChecks(chanceInfo *models.Chance) []ChanceSelfCheckData {
selfchecks := []ChanceSelfCheckData{}
mSelfChecks := chanceInfo.GetSelfCheckData()
for _, v := range mSelfChecks {
if len(v.Answer) == 0 {
continue
}
m := ChanceSelfCheckData{
Title: v.CheckItem,
Result: v.Answer,
}
selfchecks = append(selfchecks, m)
}
return selfchecks
selfChecks := []models.ChanceSelfCheckData{}
switch chanceInfo.CheckResultStatus {
case models.CheckResultStatusNone: //未提交筛查结果
selfChecks = chanceInfo.GetSelfCheckData()
if len(selfChecks) != 0 {
models.ChanceSelfCheckList(selfChecks).SetSelfChecksLevel1ByRule()
}
break
case models.CheckResultStatusWait: //未通过审核的返回所有筛查结果(一级/二级)
selfChecks = chanceInfo.GetCheckResultData()
break
default: //审核通过/不通过只显示一级
checkResult := chanceInfo.GetCheckResultData()
for i := 0; i < len(checkResult); i++ {
if selfChecks[i].ParentId == 0 {
selfChecks = append(selfChecks, checkResult[i])
}
}
}
selfChecks = models.ChanceSelfCheckList(selfChecks).Format().ClearEmpty()
checkData := []ChanceSelfCheckData{}
for i := range selfChecks {
d := ChanceSelfCheckData{
Title: selfChecks[i].CheckItem,
Result: selfChecks[i].Answer,
}
checkData = append(checkData, d)
}
return checkData
}
func AllowChanceEnableStatus(chanceid int64, companyid int64) error {
... ...