51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package entity
|
||
|
||
import (
|
||
"encoding/json"
|
||
|
||
"github.com/gogf/gf/v2/os/gtime"
|
||
)
|
||
|
||
// ContractRisk 合同条款风险点(level: high/mid/low;Laws 存支撑法条 JSON 文本)
|
||
type ContractRisk struct {
|
||
Id int64 `orm:"id" json:"id"`
|
||
TaskId int64 `orm:"task_id" json:"task_id"`
|
||
ClauseId int64 `orm:"clause_id" json:"clause_id"`
|
||
Level string `orm:"level" json:"level"`
|
||
Desc string `orm:"desc" json:"desc"`
|
||
Laws string `orm:"laws" json:"-"`
|
||
CreatedAt *gtime.Time `orm:"created_at" json:"created_at"`
|
||
}
|
||
|
||
// LawRef 支撑法条引用(laws JSON 元素)
|
||
type LawRef struct {
|
||
LawTitle string `json:"law_title"`
|
||
LawItem string `json:"law_item"`
|
||
Content string `json:"content"`
|
||
SourceFile string `json:"source_file"` // 法条所在语料文件名(判定时经 chunk 溯源填充)
|
||
}
|
||
|
||
// LawsRefs 解析 laws JSON 文本为法条引用数组(非法 JSON 返回空数组)
|
||
func (r *ContractRisk) LawsRefs() []LawRef {
|
||
if r.Laws == "" {
|
||
return nil
|
||
}
|
||
var refs []LawRef
|
||
if err := json.Unmarshal([]byte(r.Laws), &refs); err != nil {
|
||
return nil
|
||
}
|
||
return refs
|
||
}
|
||
|
||
// MarshalJSON Laws 以数组形式输出(存储为 JSON 文本,对外为结构化数组)
|
||
func (r *ContractRisk) MarshalJSON() ([]byte, error) {
|
||
type alias ContractRisk
|
||
return json.Marshal(struct {
|
||
*alias
|
||
Laws []LawRef `json:"laws"`
|
||
}{
|
||
alias: (*alias)(r),
|
||
Laws: r.LawsRefs(),
|
||
})
|
||
}
|