cc
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/redis/go-redis/v9"
|
||||
"gorm.io/gorm"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"qnc-server/config"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
"qnc-server/model/types"
|
||||
"qnc-server/service"
|
||||
"qnc-server/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LawsuitQuery struct {
|
||||
@@ -97,6 +99,7 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
||||
// 二要素核验
|
||||
twoElementsParams := map[string]any{
|
||||
"name": reqBody.Name,
|
||||
@@ -128,12 +131,14 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
}
|
||||
|
||||
} else {
|
||||
response.FailWithMessage("暂不支持企业涉诉查询", c)
|
||||
return
|
||||
// 校验企业社会统一信用代码
|
||||
isCreditCode := utils.ValidateUnifiedSocialCreditCode(reqBody.CardNo)
|
||||
if isCreditCode == false {
|
||||
response.FailWithMessage("请输入企业社会统一信用代码", c)
|
||||
return
|
||||
}
|
||||
//isCreditCode := utils.ValidateUnifiedSocialCreditCode(reqBody.CardNo)
|
||||
//if isCreditCode == false {
|
||||
// response.FailWithMessage("请输入企业社会统一信用代码", c)
|
||||
// return
|
||||
//}
|
||||
}
|
||||
|
||||
// 校验验证码
|
||||
@@ -160,8 +165,11 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
//================================================西部=============================================
|
||||
var lawsuitReq map[string]interface{}
|
||||
var reqCode string
|
||||
|
||||
authDate := GenerateDateString()
|
||||
if *reqBody.Type == types.Individual {
|
||||
encodeName, err := utils.WestDexEncrypt(reqBody.Name, "121a1e41fc1690dd6b90afbcacd80cf4")
|
||||
if err != nil {
|
||||
@@ -176,10 +184,11 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
lawsuitReq = map[string]interface{}{
|
||||
"name": encodeName,
|
||||
"id_card": encodeID,
|
||||
"name": encodeName,
|
||||
"idcard": encodeID,
|
||||
"inquired_auth": authDate,
|
||||
}
|
||||
reqCode = "G22BJ03"
|
||||
reqCode = "G35SC01"
|
||||
} else {
|
||||
encodeID, err := utils.WestDexEncrypt(reqBody.CardNo, "121a1e41fc1690dd6b90afbcacd80cf4")
|
||||
if err != nil {
|
||||
@@ -187,10 +196,19 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
lawsuitReq = map[string]interface{}{
|
||||
"ent_name": encodeID,
|
||||
encodeName, err := utils.WestDexEncrypt(reqBody.Name, "121a1e41fc1690dd6b90afbcacd80cf4")
|
||||
if err != nil {
|
||||
log.Printf("【司法涉诉】加密错误:%v", err)
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
reqCode = "Q03BJ03"
|
||||
|
||||
lawsuitReq = map[string]interface{}{
|
||||
"org_name": encodeName,
|
||||
"uscc": encodeID,
|
||||
"inquired_auth": authDate,
|
||||
}
|
||||
reqCode = "Q23SC01"
|
||||
}
|
||||
|
||||
// 发起请求并处理响应
|
||||
@@ -200,35 +218,74 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
var resp model.LawsuitResponse
|
||||
var resp model.LawsuitPersonResponse
|
||||
err = json.Unmarshal([]byte(plainText), &resp)
|
||||
if err != nil {
|
||||
handleErrorAndRefund(order, userid, "司法诉讼记录解析错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
if resp.Data.ErrCode != "200" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼响应错误:%s", resp.Data.ErrMsg), c)
|
||||
if resp.ResultCode != "200" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼响应错误:%s", resp.Message), c)
|
||||
return
|
||||
}
|
||||
|
||||
// 根据类型判断是个人信息还是公司信息
|
||||
|
||||
var respData json.RawMessage
|
||||
|
||||
if *reqBody.Type == types.Individual {
|
||||
if resp.Data.Data.PersonInfo == nil || resp.Data.Data.PersonInfo.Code == "-1000" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.PersonInfo.Msg), c)
|
||||
return
|
||||
}
|
||||
respData = resp.Data.Data.PersonInfo.Data
|
||||
} else {
|
||||
if resp.Data.Data.CompanyInfo == nil || resp.Data.Data.CompanyInfo.Code == "-1000" {
|
||||
handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.CompanyInfo.Msg), c)
|
||||
return
|
||||
}
|
||||
respData = resp.Data.Data.CompanyInfo.Data
|
||||
var respData model.LawsuitPersonData
|
||||
err = json.Unmarshal([]byte(resp.Data), &respData)
|
||||
if err != nil {
|
||||
handleErrorAndRefund(order, userid, "司法诉讼记录解析错误", c)
|
||||
return
|
||||
}
|
||||
var respDataData interface{}
|
||||
err = json.Unmarshal([]byte(respData.Data), &respDataData)
|
||||
if err != nil {
|
||||
handleErrorAndRefund(order, userid, "司法诉讼记录解析错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
//if checkIfEmpty(respDataData) || respData.Msg == "没有找到" {
|
||||
// handleErrorAndRefund(order, userid, "司法诉讼查询为空", c)
|
||||
// return
|
||||
//}
|
||||
|
||||
//根据类型判断是个人信息还是公司信息
|
||||
|
||||
//var respData json.RawMessage
|
||||
//
|
||||
//if *reqBody.Type == types.Individual {
|
||||
// if resp.Data.Data.PersonInfo == nil || resp.Data.Data.PersonInfo.Code == "-1000" {
|
||||
// handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.PersonInfo.Msg), c)
|
||||
// return
|
||||
// }
|
||||
// respData = resp.Data.Data.PersonInfo.Data
|
||||
//} else {
|
||||
// if resp.Data.Data.CompanyInfo == nil || resp.Data.Data.CompanyInfo.Code == "-1000" {
|
||||
// handleErrorAndRefund(order, userid, fmt.Sprintf("司法诉讼查询失败:%s", resp.Data.Data.CompanyInfo.Msg), c)
|
||||
// return
|
||||
// }
|
||||
// respData = resp.Data.Data.CompanyInfo.Data
|
||||
//}
|
||||
//===========================================================================================================================
|
||||
//reqData := map[string]interface{}{
|
||||
// "cardNo": reqBody.CardNo,
|
||||
// "name": reqBody.Name,
|
||||
//}
|
||||
//plainText, err := carService.CarReqYuShan("JUD009", &reqData)
|
||||
//log.Println(string(plainText))
|
||||
//if err != nil {
|
||||
// log.Printf("YuShan request at %s error: %s", "JUD009", err.Error())
|
||||
// handleErrorAndRefund(order, userid, "接口系统错误,将自动退款", c)
|
||||
// return
|
||||
//}
|
||||
//analysis, err := lawsuitQueryService.LawsuitDataAnalysis(string(plainText))
|
||||
//if err != nil {
|
||||
// if errors.Is(err, utils.ErrNoRecord) {
|
||||
// handleErrorAndRefund(order, userid, "综合涉诉查询为空,将自动退款", c)
|
||||
// } else {
|
||||
// handleErrorAndRefund(order, userid, "综合涉诉解析错误,将自动退款", c)
|
||||
// }
|
||||
// return
|
||||
//}
|
||||
|
||||
var query model.Query
|
||||
query.OrderID = order.ID
|
||||
@@ -236,7 +293,7 @@ func (l *LawsuitQuery) queryListV2(c *gin.Context) {
|
||||
query.Userid = userid
|
||||
query.ProductID = order.ProductID
|
||||
db.DB.Create(&query)
|
||||
uniqueID := utils.SetCacheData(ctx, respData)
|
||||
uniqueID := utils.SetCacheData(ctx, []interface{}{respDataData})
|
||||
// 更新订单状态并返回成功响应
|
||||
orderService.OrderConsumed(order)
|
||||
response.OkWithData(gin.H{
|
||||
@@ -270,21 +327,6 @@ func (l *LawsuitQuery) GetRecord(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
//userid := utils.GetUserID(c)
|
||||
//record, err := lawsuitQueryService.QueryLawsuitByOrder(req.ID, userid)
|
||||
//if err != nil {
|
||||
// log.Printf("【司法涉诉】获取司法涉诉记录错误:%v", err)
|
||||
// notifyService.SendNotification("系统错误,获取司法涉诉记录错误,请及时处理", "司法涉诉", userid, record.OrderID)
|
||||
// response.FailRefund(c)
|
||||
// return
|
||||
//}
|
||||
//var resp any
|
||||
//err = json.Unmarshal([]byte(record.Resp), &resp)
|
||||
//if err != nil {
|
||||
// log.Printf("【司法涉诉】获取司法涉诉解析错误:%v", err)
|
||||
// notifyService.SendNotification("系统错误,获取司法涉诉解析错误,请及时处理", "司法涉诉", userid, record.OrderID)
|
||||
// return
|
||||
//}
|
||||
data, err := utils.GetCacheData(ctx, req.ID)
|
||||
if err != nil {
|
||||
if errors.Is(err, redis.Nil) {
|
||||
@@ -295,5 +337,61 @@ func (l *LawsuitQuery) GetRecord(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if checkIfEmpty(data) {
|
||||
// 判断data是否是string类型并且等于"查询成功无结果"
|
||||
//if strData, ok := data.(string); ok && strData == "查询成功无结果" {
|
||||
|
||||
// 读取empty.json文件
|
||||
emptyData, readErr := ioutil.ReadFile("empty.json")
|
||||
if readErr != nil {
|
||||
log.Printf("系统错误: 无法读取empty.json:%v", readErr)
|
||||
response.FailWithMessage("系统错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 将empty.json的内容反序列化为map或者结构体
|
||||
var jsonData []map[string]interface{}
|
||||
if jsonErr := json.Unmarshal(emptyData, &jsonData); jsonErr != nil {
|
||||
log.Printf("系统错误: 无法解析empty.json:%v", readErr)
|
||||
response.FailWithMessage("系统错误", c)
|
||||
return
|
||||
}
|
||||
|
||||
// 返回反序列化后的JSON数据
|
||||
response.OkWithData(jsonData, c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(data, c)
|
||||
}
|
||||
func GenerateDateString() string {
|
||||
// 获取当前时间
|
||||
now := time.Now()
|
||||
// 格式化当前日期为YYYYMMDD
|
||||
today := now.Format("20060102")
|
||||
// 获取明天的日期
|
||||
tomorrow := now.AddDate(0, 0, 1).Format("20060102")
|
||||
// 拼接成所需格式
|
||||
return today + "-" + tomorrow
|
||||
}
|
||||
|
||||
// 判断函数
|
||||
func checkIfEmpty(data interface{}) bool {
|
||||
// 判断是否为 nil
|
||||
if data == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// 判断是否为空数组
|
||||
if arr, ok := data.([]interface{}); ok {
|
||||
return len(arr) == 0
|
||||
}
|
||||
|
||||
// 判断是否为空对象(空 map)
|
||||
if obj, ok := data.(map[string]interface{}); ok {
|
||||
return len(obj) == 0
|
||||
}
|
||||
|
||||
// 如果不是上述情况,表示不为空
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user