...
|
...
|
@@ -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 {
|
|
|
continue
|
|
|
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
|
|
|
}
|
|
|
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 {
|
|
|
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++
|
|
|
}
|
|
|
data = append(data, temp[i])
|
|
|
}
|
|
|
} 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)
|
|
|
//只有一级维度的必须填写
|
|
|
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
|
...
|
...
|
|