CNLiveVitaeViewModel.swift
4.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//
// CNLiveVitaeViewModel.swift
// metaCode
//
// Created by zx on 2024/7/12.
// 数字简历
import Foundation
import CNLiveRequestBastKit
class CNLiveVitaeViewModel:NSObject{
/*
查看简历
参数 vsid 实名对象id
参数 type 1简历信息 2官方认证 3证书 4工作经历 4获奖情况
*/
static func getVitae(vsid:String,type:NSInteger,resultBlock: @escaping downSlideResultBlock) {
let param = NSMutableDictionary()
param.setValue(vsid, forKey: "vsid")
param.setValue("\(type)", forKey: "type")
CNLiveNetworking.setAllowRequestDefaultArgument(true)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setupDSRequest(true)
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.requestNetwork(with: .GET, urlString: APPBaseMCUrl+"/userApi/getVitae", param: param as! [String : String], cacheType: .networkOnly) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let dataDic = resp["data"] as! NSDictionary
let shopDetailModel = newDictionaryToModel(dataDic as! [String : Any], CNLiveVitaeModel.self)
resultBlock(shopDetailModel,.success)
}else{
resultBlock(NSNull(),.failed)
}
}
}
/*
保存简历/更新简历
参数 vsid 实名对象id
参数 type 1简历信息 2官方认证 3证书 4工作经历 4获奖情况
*/
static func saveVitae(city:String,icon:String,isSave:Bool,id:NSInteger,phone:String,profession:String,professionId:NSInteger,selfIntroduction:String,showAddress:Bool,showAge:Bool,showAwards:Bool,showPhone:Bool,updateTime:String,vsid:String,workTime:String,resultBlock: @escaping downSlideResultBlock) {
let values = NSMutableDictionary()
values.addEntries(from: ["city":city])
values.addEntries(from: ["icon":icon])
//简历为nil保存简历时 不传id; 更新简历时id传简历的vitaeid
if !isSave{
values.addEntries(from: ["id":id])
}
values.addEntries(from: ["phone":phone])
values.addEntries(from: ["profession":profession])
values.addEntries(from: ["professionId":professionId])
values.addEntries(from: ["selfIntroduction":selfIntroduction])
values.addEntries(from: ["showAddress":showAddress])
values.addEntries(from: ["showAge":showAge])
values.addEntries(from: ["showAwards":showAwards])
values.addEntries(from: ["showPhone":showPhone])
values.addEntries(from: ["updateTime":updateTime])
values.addEntries(from: ["vsid":vsid])
values.addEntries(from: ["workTime":workTime])
do {
let request = URLRequest.init(url: URL.init(string: APPBaseMCUrl+"/userApi/saveVitae")!) as! NSMutableURLRequest
request.httpMethod = "POST"
request.timeoutInterval = 10
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
let data = try JSONSerialization.data(withJSONObject: values, options: .prettyPrinted)
request.httpBody = data
showLoading(message: "")
let custom_param = NSMutableDictionary()
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appId, forKey: "appId")
custom_param.setValue(CNLiveMCEnvironmentManager.shared.appKey, forKey: "appKey")
CNLiveNetworking.setupCustomParam(custom_param as? [String : String])
CNLiveNetworking.setAllowRequestDefaultArgument(false)
CNLiveNetworking.setupShowDataResult(false)
CNLiveNetworking.setBuildCustomUrlRequest(request as URLRequest) { task, result, error in
hiddenLoading()
if (error == nil) {
let resp = result as! NSDictionary
let errorCode = "\(resp["errorCode"] ?? "0")"
if (errorCode == "0") {
resultBlock(true,.success)
} else {
showMessage(message: resp["errorMessage"] as! String)
resultBlock(NSNull(),.failed)
}
} else {
if CNLiveNetworking.isNetworking() {
showMessage(message: "上传失败")
resultBlock(NSNull(),.failed)
} else {
showMessage(message: "似乎与网络断开链接")
resultBlock(NSNull(),.noNetwork)
}
}
}
} catch {
showMessage(message: "上传失败")
resultBlock(NSNull(),.failed)
}
}
}