f
This commit is contained in:
@@ -0,0 +1,471 @@
|
||||
package dwbg
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// buildJudicialLeaseReport maps FLXG7E8F to Sinan judicialLeaseReport.
|
||||
func buildJudicialLeaseReport(apiData map[string]interface{}) map[string]interface{} {
|
||||
report := emptyJudicialLeaseReport()
|
||||
flxg := flxg7e8fMap(apiData)
|
||||
if flxg == nil {
|
||||
return report
|
||||
}
|
||||
judicialData := asMap(flxg["judicial_data"])
|
||||
if judicialData == nil {
|
||||
return report
|
||||
}
|
||||
|
||||
lawsuitStat := asMap(judicialData["lawsuitStat"])
|
||||
courtInfo, newMult := judicialCourtMaps(report)
|
||||
if courtInfo == nil || newMult == nil {
|
||||
return report
|
||||
}
|
||||
|
||||
if lawsuitStat != nil {
|
||||
courtInfo["civilCasesCount"] = lawsuitCasesCount(lawsuitStat, "civil")
|
||||
courtInfo["criminalCasesCount"] = lawsuitCasesCount(lawsuitStat, "criminal")
|
||||
courtInfo["administrativeCasesCount"] = lawsuitCasesCount(lawsuitStat, "administrative")
|
||||
courtInfo["preservationCasesCount"] = lawsuitPreservationCount(lawsuitStat)
|
||||
courtInfo["enforcementCasesCount"] = lawsuitCasesCount(lawsuitStat, "implement")
|
||||
courtInfo["bankruptcyCasesCount"] = lawsuitCasesCount(lawsuitStat, "bankrupt")
|
||||
|
||||
if cases := convertSinanCaseList(lawsuitStat, "civil"); len(cases) > 0 {
|
||||
newMult["civilCases"] = cases
|
||||
}
|
||||
if cases := convertSinanCaseList(lawsuitStat, "criminal"); len(cases) > 0 {
|
||||
newMult["criminalCases"] = cases
|
||||
}
|
||||
if cases := convertSinanCaseList(lawsuitStat, "administrative"); len(cases) > 0 {
|
||||
newMult["administrativeCases"] = cases
|
||||
}
|
||||
if cases := convertSinanCaseList(lawsuitStat, "preservation"); len(cases) > 0 {
|
||||
newMult["preservationCases"] = cases
|
||||
}
|
||||
if cases := convertSinanCaseList(lawsuitStat, "implement"); len(cases) > 0 {
|
||||
newMult["enforcementCases"] = cases
|
||||
}
|
||||
if cases := convertSinanCaseList(lawsuitStat, "bankrupt"); len(cases) > 0 {
|
||||
newMult["bankruptcyCases"] = cases
|
||||
}
|
||||
|
||||
if globalCount := asMap(lawsuitStat["count"]); globalCount != nil {
|
||||
newMult["caseCounts"] = convertFLXGCountToSinan(globalCount)
|
||||
}
|
||||
for _, pair := range []struct {
|
||||
flxgKey string
|
||||
sinanKey string
|
||||
}{
|
||||
{"civil", "civilCaseCounts"},
|
||||
{"criminal", "criminalCaseCounts"},
|
||||
{"administrative", "administrativeCaseCounts"},
|
||||
{"preservation", "preservationCaseCounts"},
|
||||
{"implement", "enforcementCaseCounts"},
|
||||
{"bankrupt", "bankruptcyCaseCounts"},
|
||||
} {
|
||||
if bucket := asMap(lawsuitStat[pair.flxgKey]); bucket != nil {
|
||||
if count := asMap(bucket["count"]); count != nil {
|
||||
newMult[pair.sinanKey] = convertFLXGCountToSinan(count)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if breachList, ok := judicialData["breachCaseList"].([]interface{}); ok && len(breachList) > 0 {
|
||||
disinCases := make([]interface{}, 0, len(breachList))
|
||||
for _, item := range breachList {
|
||||
if caseMap, ok := item.(map[string]interface{}); ok {
|
||||
if converted := convertSinanDisinCase(caseMap); converted != nil {
|
||||
disinCases = append(disinCases, converted)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(disinCases) > 0 {
|
||||
newMult["disinCases"] = disinCases
|
||||
}
|
||||
}
|
||||
|
||||
if limitList, ok := judicialData["consumptionRestrictionList"].([]interface{}); ok && len(limitList) > 0 {
|
||||
limitCases := make([]interface{}, 0, len(limitList))
|
||||
for _, item := range limitList {
|
||||
if caseMap, ok := item.(map[string]interface{}); ok {
|
||||
if converted := convertSinanLimitCase(caseMap); converted != nil {
|
||||
limitCases = append(limitCases, converted)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(limitCases) > 0 {
|
||||
newMult["limitCases"] = limitCases
|
||||
}
|
||||
}
|
||||
|
||||
report["caseOverviewInfo"] = buildCaseOverviewInfo(lawsuitStat, judicialData, courtInfo)
|
||||
return report
|
||||
}
|
||||
|
||||
func judicialCourtMaps(report map[string]interface{}) (courtInfo, newMult map[string]interface{}) {
|
||||
ci, ok := report["courtInfo"].(map[string]interface{})
|
||||
if !ok || ci == nil {
|
||||
return nil, nil
|
||||
}
|
||||
nm, ok := ci["newMultCourtInfo"].(map[string]interface{})
|
||||
if !ok || nm == nil {
|
||||
return nil, nil
|
||||
}
|
||||
return ci, nm
|
||||
}
|
||||
|
||||
func lawsuitCasesCount(lawsuitStat map[string]interface{}, key string) int {
|
||||
bucket := asMap(lawsuitStat[key])
|
||||
if bucket == nil {
|
||||
return 0
|
||||
}
|
||||
if cases, ok := bucket["cases"].([]interface{}); ok && len(cases) > 0 {
|
||||
return len(cases)
|
||||
}
|
||||
if count := asMap(bucket["count"]); count != nil {
|
||||
return parseIntValue(count["count_total"])
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func lawsuitPreservationCount(lawsuitStat map[string]interface{}) int {
|
||||
bucket := asMap(lawsuitStat["preservation"])
|
||||
if bucket == nil {
|
||||
return 0
|
||||
}
|
||||
if count := asMap(bucket["count"]); count != nil {
|
||||
if total := parseIntValue(count["count_total"]); total > 0 {
|
||||
return total
|
||||
}
|
||||
}
|
||||
return lawsuitCasesCount(lawsuitStat, "preservation")
|
||||
}
|
||||
|
||||
func convertSinanCaseList(lawsuitStat map[string]interface{}, key string) []interface{} {
|
||||
bucket := asMap(lawsuitStat[key])
|
||||
if bucket == nil {
|
||||
return nil
|
||||
}
|
||||
cases, ok := bucket["cases"].([]interface{})
|
||||
if !ok || len(cases) == 0 {
|
||||
return nil
|
||||
}
|
||||
out := make([]interface{}, 0, len(cases))
|
||||
for _, item := range cases {
|
||||
caseMap, ok := item.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
if converted := convertSinanLegalCase(caseMap); converted != nil {
|
||||
out = append(out, converted)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func convertSinanLegalCase(caseMap map[string]interface{}) map[string]interface{} {
|
||||
caseNumber := xypString(caseMap, "c_ah")
|
||||
if caseNumber == "" {
|
||||
return nil
|
||||
}
|
||||
info := map[string]interface{}{
|
||||
"caseNumber": caseNumber,
|
||||
"nssdw": xypString(caseMap, "n_ssdw"),
|
||||
"caseStatus": xypString(caseMap, "n_ajjzjd"),
|
||||
"najlx": xypString(caseMap, "n_ajlx"),
|
||||
"cdsrxx": formatCdsrxx(caseMap["c_dsrxx"]),
|
||||
"nslcx": xypString(caseMap, "n_slcx"),
|
||||
"zxfy": xypString(caseMap, "n_jbfy"),
|
||||
"njbfy": xypString(caseMap, "n_jbfy"),
|
||||
"dlarq": xypString(caseMap, "d_larq"),
|
||||
"djarq": xypString(caseMap, "d_jarq"),
|
||||
"njafs": xypString(caseMap, "n_jafs"),
|
||||
"nqsbdje": formatNumericValue(caseMap["n_qsbdje"]),
|
||||
"njabdje": formatNumericValue(caseMap["n_jabdje"]),
|
||||
"nsqzxbdje": formatNumericValue(caseMap["n_sqzxbdje"]),
|
||||
"nsjdwje": formatNumericValue(caseMap["n_sjdwje"]),
|
||||
"nwzxje": formatNumericValue(caseMap["n_wzxje"]),
|
||||
"npjVictory": xypString(caseMap, "n_pj_victory"),
|
||||
"cgkwsDsr": xypString(caseMap, "c_gkws_dsr"),
|
||||
"cgkwsPjjg": xypString(caseMap, "c_gkws_pjjg"),
|
||||
"najbs": xypString(caseMap, "n_ajbs"),
|
||||
"nlaayTree": firstNonEmpty(xypString(caseMap, "n_laay_tree"), xypString(caseMap, "n_jaay_tree")),
|
||||
"nfzje": formatNumericValue(caseMap["n_fzje"]),
|
||||
"npcpcje": formatNumericValue(caseMap["n_pcpcje"]),
|
||||
"nccxzxje": formatNumericValue(caseMap["n_ccxzxje"]),
|
||||
"cahHx": "",
|
||||
"cahHxBs": "",
|
||||
}
|
||||
if cAhHx := xypString(caseMap, "c_ah_hx"); cAhHx != "" {
|
||||
parts := strings.SplitN(cAhHx, ":", 2)
|
||||
info["cahHx"] = strings.TrimSpace(parts[0])
|
||||
if len(parts) == 2 {
|
||||
info["cahHxBs"] = strings.TrimSpace(parts[1])
|
||||
}
|
||||
}
|
||||
return info
|
||||
}
|
||||
|
||||
func formatCdsrxx(raw interface{}) string {
|
||||
list, ok := raw.([]interface{})
|
||||
if !ok || len(list) == 0 {
|
||||
return ""
|
||||
}
|
||||
parts := make([]string, 0, len(list))
|
||||
for _, item := range list {
|
||||
m, ok := item.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
role := xypString(m, "n_ssdw")
|
||||
name := xypString(m, "c_mc")
|
||||
typ := xypString(m, "n_dsrlx")
|
||||
if name == "" {
|
||||
continue
|
||||
}
|
||||
parts = append(parts, fmt.Sprintf("%s%s\u3010%s\u3011", role, name, typ))
|
||||
}
|
||||
return strings.Join(parts, "\uff1b")
|
||||
}
|
||||
|
||||
func convertFLXGCountToSinan(count map[string]interface{}) map[string]interface{} {
|
||||
out := emptyCaseCounts()
|
||||
out["totalCasesCounts"] = countToString(count["count_total"])
|
||||
out["totalJieCaseCounts"] = countToString(count["count_jie_total"])
|
||||
out["totalWeiCaseCounts"] = countToString(count["count_wei_total"])
|
||||
out["totalCaseAmounts"] = countToString(count["money_total"])
|
||||
out["totalJieAmountCases"] = countToString(count["money_jie_total"])
|
||||
out["totalWeiAmountCases"] = countToString(count["money_wei_total"])
|
||||
out["beigaoTotalCasesCounts"] = countToString(count["count_beigao"])
|
||||
out["beigaoTotalJieCaseCounts"] = countToString(count["count_jie_beigao"])
|
||||
out["beigaoTotalWeiCaseCounts"] = countToString(count["count_wei_beigao"])
|
||||
out["beigaoTotalCaseAmounts"] = countToString(count["money_beigao"])
|
||||
out["beigaoTotalJieAmountCases"] = countToString(count["money_jie_beigao"])
|
||||
out["beigaoTotalWeiAmountCases"] = countToString(count["money_wei_beigao"])
|
||||
out["yuangaoTotalCasesCounts"] = countToString(count["count_yuangao"])
|
||||
out["yuangaoTotalJieCaseCounts"] = countToString(count["count_jie_yuangao"])
|
||||
out["yuangaoTotalWeiCaseCounts"] = countToString(count["count_wei_yuangao"])
|
||||
out["yuangaoTotalCaseAmounts"] = countToString(count["money_yuangao"])
|
||||
out["yuangaoTotalJieAmountCases"] = countToString(count["money_jie_yuangao"])
|
||||
out["yuangaoTotalWeiAmountCases"] = countToString(count["money_wei_yuangao"])
|
||||
out["otherTotalCasesCounts"] = countToString(count["count_other"])
|
||||
out["otherTotalJieCaseCounts"] = countToString(count["count_jie_other"])
|
||||
out["otherTotalWeiCaseCounts"] = countToString(count["count_wei_other"])
|
||||
out["otherTotalCaseAmounts"] = countToString(count["money_other"])
|
||||
out["otherTotalJieAmountCases"] = countToString(count["money_jie_other"])
|
||||
out["otherTotalWeiAmountCases"] = countToString(count["money_wei_other"])
|
||||
out["caseActionDistribution"] = statOrDash(count["ay_stat"])
|
||||
out["localDistribution"] = statOrDash(count["area_stat"])
|
||||
out["timeDistribution"] = statOrDash(count["larq_stat"])
|
||||
out["caseCloselDistribution"] = statOrDash(count["jafs_stat"])
|
||||
return out
|
||||
}
|
||||
|
||||
func countToString(val interface{}) string {
|
||||
if val == nil {
|
||||
return "0"
|
||||
}
|
||||
switch v := val.(type) {
|
||||
case string:
|
||||
if strings.TrimSpace(v) == "" {
|
||||
return "0"
|
||||
}
|
||||
return v
|
||||
case float64:
|
||||
return formatNumericValue(v)
|
||||
case int:
|
||||
return formatNumericValue(v)
|
||||
case int64:
|
||||
return formatNumericValue(v)
|
||||
default:
|
||||
return "0"
|
||||
}
|
||||
}
|
||||
|
||||
func statOrDash(val interface{}) string {
|
||||
s := strings.TrimSpace(fmt.Sprint(val))
|
||||
if s == "" || s == "<nil>" {
|
||||
return "-"
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
func buildCaseOverviewInfo(lawsuitStat map[string]interface{}, judicialData map[string]interface{}, courtInfo map[string]interface{}) map[string]interface{} {
|
||||
overview := emptyCaseOverviewInfo()
|
||||
|
||||
if lawsuitStat != nil {
|
||||
if globalCount := asMap(lawsuitStat["count"]); globalCount != nil {
|
||||
overview["beigaoTotalCasesCounts"] = parseIntValue(globalCount["count_beigao"])
|
||||
overview["beigaoTotalWeiCaseCounts"] = parseIntValue(globalCount["count_wei_beigao"])
|
||||
overview["beigaoTotalCaseAmounts"] = parseIntValue(globalCount["money_beigao"])
|
||||
overview["leastCaseTime"] = extractLatestCaseTime(statOrDash(globalCount["larq_stat"]))
|
||||
}
|
||||
}
|
||||
|
||||
overview["executionCaseCounts"] = courtInfo["enforcementCasesCount"]
|
||||
|
||||
if breachList, ok := judicialData["breachCaseList"].([]interface{}); ok && len(breachList) > 0 {
|
||||
overview["disinCaseCounts"] = 1
|
||||
}
|
||||
if limitList, ok := judicialData["consumptionRestrictionList"].([]interface{}); ok && len(limitList) > 0 {
|
||||
overview["limitCaseCounts"] = 1
|
||||
}
|
||||
|
||||
return overview
|
||||
}
|
||||
|
||||
func extractLatestCaseTime(stat string) string {
|
||||
if stat == "" || stat == "-" {
|
||||
return ""
|
||||
}
|
||||
parts := strings.Split(stat, ",")
|
||||
if len(parts) == 0 {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(parts[len(parts)-1])
|
||||
}
|
||||
|
||||
func convertSinanDisinCase(caseMap map[string]interface{}) map[string]interface{} {
|
||||
caseNumber := xypString(caseMap, "caseNumber")
|
||||
if caseNumber == "" {
|
||||
return nil
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"caseNumber": caseNumber,
|
||||
"court": xypString(caseMap, "executiveCourt"),
|
||||
"filingTime": xypString(caseMap, "fileDate"),
|
||||
"caseStatus": xypString(caseMap, "fulfillStatus"),
|
||||
}
|
||||
}
|
||||
|
||||
func convertSinanLimitCase(caseMap map[string]interface{}) map[string]interface{} {
|
||||
caseNumber := xypString(caseMap, "caseNumber")
|
||||
if caseNumber == "" {
|
||||
return nil
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"caseNumber": caseNumber,
|
||||
"court": xypString(caseMap, "executiveCourt"),
|
||||
"filingTime": xypString(caseMap, "fileDate"),
|
||||
}
|
||||
}
|
||||
|
||||
func firstNonEmpty(values ...string) string {
|
||||
for _, v := range values {
|
||||
if strings.TrimSpace(v) != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func hasJudicialCases(apiData map[string]interface{}) bool {
|
||||
flxg := flxg7e8fMap(apiData)
|
||||
if flxg == nil {
|
||||
return false
|
||||
}
|
||||
judicialData := asMap(flxg["judicial_data"])
|
||||
if judicialData == nil {
|
||||
return false
|
||||
}
|
||||
lawsuitStat := asMap(judicialData["lawsuitStat"])
|
||||
if lawsuitStat != nil {
|
||||
for _, key := range []string{"civil", "criminal", "administrative", "preservation", "implement", "bankrupt"} {
|
||||
if lawsuitCasesCount(lawsuitStat, key) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
if list, ok := judicialData["breachCaseList"].([]interface{}); ok && len(list) > 0 {
|
||||
return true
|
||||
}
|
||||
if list, ok := judicialData["consumptionRestrictionList"].([]interface{}); ok && len(list) > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func hasPreservationCases(apiData map[string]interface{}) bool {
|
||||
flxg := flxg7e8fMap(apiData)
|
||||
if flxg == nil {
|
||||
return false
|
||||
}
|
||||
judicialData := asMap(flxg["judicial_data"])
|
||||
if judicialData == nil {
|
||||
return false
|
||||
}
|
||||
lawsuitStat := asMap(judicialData["lawsuitStat"])
|
||||
if lawsuitStat == nil {
|
||||
return false
|
||||
}
|
||||
return lawsuitPreservationCount(lawsuitStat) > 0
|
||||
}
|
||||
|
||||
func hasLegalCases(apiData map[string]interface{}) bool {
|
||||
flxg := flxg7e8fMap(apiData)
|
||||
if flxg == nil {
|
||||
return false
|
||||
}
|
||||
judicialData := asMap(flxg["judicial_data"])
|
||||
if judicialData == nil {
|
||||
return false
|
||||
}
|
||||
lawsuitStat := asMap(judicialData["lawsuitStat"])
|
||||
if lawsuitStat == nil {
|
||||
return false
|
||||
}
|
||||
for _, key := range []string{"civil", "criminal", "administrative"} {
|
||||
if lawsuitCasesCount(lawsuitStat, key) > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func hasExecutionCases(apiData map[string]interface{}) bool {
|
||||
flxg := flxg7e8fMap(apiData)
|
||||
if flxg == nil {
|
||||
return false
|
||||
}
|
||||
judicialData := asMap(flxg["judicial_data"])
|
||||
if judicialData == nil {
|
||||
return false
|
||||
}
|
||||
lawsuitStat := asMap(judicialData["lawsuitStat"])
|
||||
if lawsuitStat == nil {
|
||||
return false
|
||||
}
|
||||
return lawsuitCasesCount(lawsuitStat, "implement") > 0
|
||||
}
|
||||
|
||||
func hasDisinCases(apiData map[string]interface{}) bool {
|
||||
flxg := flxg7e8fMap(apiData)
|
||||
if flxg == nil {
|
||||
return false
|
||||
}
|
||||
judicialData := asMap(flxg["judicial_data"])
|
||||
if judicialData == nil {
|
||||
return false
|
||||
}
|
||||
list, ok := judicialData["breachCaseList"].([]interface{})
|
||||
return ok && len(list) > 0
|
||||
}
|
||||
|
||||
func hasLimitCases(apiData map[string]interface{}) bool {
|
||||
flxg := flxg7e8fMap(apiData)
|
||||
if flxg == nil {
|
||||
return false
|
||||
}
|
||||
judicialData := asMap(flxg["judicial_data"])
|
||||
if judicialData == nil {
|
||||
return false
|
||||
}
|
||||
list, ok := judicialData["consumptionRestrictionList"].([]interface{})
|
||||
return ok && len(list) > 0
|
||||
}
|
||||
|
||||
func hasCourtViolator(apiData map[string]interface{}) bool {
|
||||
return hasExecutionCases(apiData) || hasDisinCases(apiData)
|
||||
}
|
||||
Reference in New Issue
Block a user