Commit db6ffc982ceb5d9c3d60c394d24f88e5d9776347
1 parent
13df4a5f
* [x] 数字简历-省市区只保留省
* [x] 数字简历-工作经验不足1年时换成几个月
Showing
3 changed files
with
202 additions
and
64 deletions
metaCode/Classes/Main/HomePage/Controller/DigitalAuth/数字简历相关页面/CNLiveDigitalResumeInfoController.swift
| ... | ... | @@ -381,12 +381,13 @@ class CNLiveDigitalResumeInfoController:CNLiveBaseViewController, UITextFieldDel |
| 381 | 381 | if let seDay = userDic["jianli_workTime"]{ |
| 382 | 382 | //设置过工作日期 |
| 383 | 383 | let seleDay = seDay as! String |
| 384 | - var yearStr = "" | |
| 385 | - if let workExperience = self.calculateWorkExperience(fromDateString: seleDay){ | |
| 386 | - yearStr = "\(seleDay)(\(workExperience)年经验)" | |
| 387 | - }else{ | |
| 388 | - yearStr = seleDay | |
| 389 | - } | |
| 384 | + var yearStr = self.calculateWorkExperience(fromDateString: seleDay) | |
| 385 | + yearStr = "\(seleDay)(\(yearStr))" | |
| 386 | +// if let workExperience = self.calculateWorkExperience(fromDateString: seleDay){ | |
| 387 | +// yearStr = "\(seleDay)(\(workExperience)年经验)" | |
| 388 | +// }else{ | |
| 389 | +// yearStr = seleDay | |
| 390 | +// } | |
| 390 | 391 | |
| 391 | 392 | self.canjiaRightTitleLabel.text = yearStr |
| 392 | 393 | }else{ |
| ... | ... | @@ -442,33 +443,67 @@ class CNLiveDigitalResumeInfoController:CNLiveBaseViewController, UITextFieldDel |
| 442 | 443 | } |
| 443 | 444 | } |
| 444 | 445 | } |
| 445 | - | |
| 446 | - //计算工作年限 | |
| 447 | - func calculateWorkExperience(fromDateString: String) -> Int? { | |
| 446 | + //计算工作年限 "2023.07.03" | |
| 447 | + func calculateWorkExperience(fromDateString: String) -> String { | |
| 448 | 448 | let formatter = DateFormatter() |
| 449 | 449 | formatter.dateFormat = "yyyy-MM-dd" |
| 450 | 450 | formatter.timeZone = TimeZone(abbreviation: "UTC")! // 确保时区一致,或者根据需要调整 |
| 451 | 451 | |
| 452 | 452 | guard let startDate = formatter.date(from: fromDateString) else { |
| 453 | - return nil | |
| 453 | + return "" | |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | let calendar = Calendar.current |
| 457 | 457 | let currentDate = Date() |
| 458 | 458 | |
| 459 | 459 | // 计算年份差,这里我们不需要精确的月份和日期,所以只需要年份组件 |
| 460 | - let components = calendar.dateComponents([.year], from: startDate, to: currentDate) | |
| 461 | - guard let yearDifference = components.year else { | |
| 462 | - return nil | |
| 460 | + let components = calendar.dateComponents([.year, .month], from: startDate, to: currentDate) | |
| 461 | + // 提取年和月 | |
| 462 | + let years = components.year ?? 0 | |
| 463 | + let months = components.month ?? 0 | |
| 464 | + | |
| 465 | + // 格式化输出 | |
| 466 | + if years > 0 { | |
| 467 | + return "\(years)年经验" | |
| 468 | + } else if months > 0 { | |
| 469 | + return "\(months)个月经验" | |
| 470 | + } else { | |
| 471 | + return "0个月经验" | |
| 463 | 472 | } |
| 464 | - | |
| 465 | - // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 466 | - // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 467 | - let roundedYearDifference = round(Double(yearDifference)) | |
| 468 | - | |
| 469 | - // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 470 | - return Int(roundedYearDifference) | |
| 473 | + | |
| 474 | +// // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 475 | +// // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 476 | +// let roundedYearDifference = round(Double(yearDifference)) | |
| 477 | +// | |
| 478 | +// // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 479 | +// return Int(roundedYearDifference) | |
| 471 | 480 | } |
| 481 | +// //计算工作年限 | |
| 482 | +// func calculateWorkExperience(fromDateString: String) -> Int? { | |
| 483 | +// let formatter = DateFormatter() | |
| 484 | +// formatter.dateFormat = "yyyy-MM-dd" | |
| 485 | +// formatter.timeZone = TimeZone(abbreviation: "UTC")! // 确保时区一致,或者根据需要调整 | |
| 486 | +// | |
| 487 | +// guard let startDate = formatter.date(from: fromDateString) else { | |
| 488 | +// return nil | |
| 489 | +// } | |
| 490 | +// | |
| 491 | +// let calendar = Calendar.current | |
| 492 | +// let currentDate = Date() | |
| 493 | +// | |
| 494 | +// // 计算年份差,这里我们不需要精确的月份和日期,所以只需要年份组件 | |
| 495 | +// let components = calendar.dateComponents([.year], from: startDate, to: currentDate) | |
| 496 | +// guard let yearDifference = components.year else { | |
| 497 | +// return nil | |
| 498 | +// } | |
| 499 | +// | |
| 500 | +// // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 501 | +// // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 502 | +// let roundedYearDifference = round(Double(yearDifference)) | |
| 503 | +// | |
| 504 | +// // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 505 | +// return Int(roundedYearDifference) | |
| 506 | +// } | |
| 472 | 507 | |
| 473 | 508 | deinit { |
| 474 | 509 | |
| ... | ... | @@ -609,11 +644,12 @@ class CNLiveDigitalResumeInfoController:CNLiveBaseViewController, UITextFieldDel |
| 609 | 644 | var yearStr = ""//UI展示str |
| 610 | 645 | var textstr = ""//接口传"2024-06-18" |
| 611 | 646 | if let textStr = text as? String{ |
| 612 | - if let workExperience = self?.calculateWorkExperience(fromDateString: textStr){ | |
| 613 | - yearStr = "\(textStr)(\(workExperience)年经验)" | |
| 614 | - }else{ | |
| 615 | - yearStr = textStr | |
| 616 | - } | |
| 647 | + yearStr = self?.calculateWorkExperience(fromDateString: textStr) ?? "" | |
| 648 | +// if let workExperience = self?.calculateWorkExperience(fromDateString: textStr){ | |
| 649 | +// yearStr = "\(textStr)(\(workExperience)年经验)" | |
| 650 | +// }else{ | |
| 651 | +// yearStr = textStr | |
| 652 | +// } | |
| 617 | 653 | textstr = textStr |
| 618 | 654 | }else{ |
| 619 | 655 | yearStr = "请选择" | ... | ... |
metaCode/Classes/Main/HomePage/View/DigitalAuthViews/DigitalResume/CNLiveDigitalResumeCell.swift
| ... | ... | @@ -817,7 +817,13 @@ class CNLiveDigitalResumeCell: UITableViewCell { |
| 817 | 817 | self.hangyeImgView.isHidden = true |
| 818 | 818 | } |
| 819 | 819 | if model.vitae?.city.count ?? 0 > 0 && model.vitae?.showAddress == true{ |
| 820 | - self.weizhiTitleLabel.text = " | "+model.vitae!.city | |
| 820 | + let shengStr = self.extractProvinceOrMunicipalityFromAddress(address: model.vitae!.city) | |
| 821 | + if shengStr?.count ?? 0 > 0{ | |
| 822 | + self.weizhiTitleLabel.text = " | "+shengStr! | |
| 823 | + }else{ | |
| 824 | + self.weizhiTitleLabel.text = " | "+(shengStr ?? "") | |
| 825 | + } | |
| 826 | +// self.weizhiTitleLabel.text = " | "+shengStr//model.vitae!.city | |
| 821 | 827 | }else{ |
| 822 | 828 | self.weizhiTitleLabel.text = ""//" | 位置未授权" |
| 823 | 829 | } |
| ... | ... | @@ -830,12 +836,13 @@ class CNLiveDigitalResumeCell: UITableViewCell { |
| 830 | 836 | }else{ |
| 831 | 837 | workTimeStr = model.vitae!.workTime |
| 832 | 838 | } |
| 833 | - | |
| 834 | - if let workExperience = self.calculateWorkExperience(fromDateString: workTimeStr){ | |
| 835 | - yearStr = "\(workExperience)年经验" | |
| 836 | - }else{ | |
| 837 | - yearStr = "" | |
| 838 | - } | |
| 839 | + | |
| 840 | + yearStr = self.calculateWorkExperience(fromDateString: workTimeStr) | |
| 841 | +// if let workExperience = self.calculateWorkExperience(fromDateString: workTimeStr){ | |
| 842 | +// yearStr = "\(workExperience)年经验" | |
| 843 | +// }else{ | |
| 844 | +// yearStr = "" | |
| 845 | +// } | |
| 839 | 846 | |
| 840 | 847 | self.workTitleLabel.text = yearStr//model.vitae!.workTime |
| 841 | 848 | |
| ... | ... | @@ -853,31 +860,61 @@ class CNLiveDigitalResumeCell: UITableViewCell { |
| 853 | 860 | self.huojiangDetailNumberTitleLabel.text = "\(model.awards.count)" |
| 854 | 861 | } |
| 855 | 862 | |
| 856 | - //计算工作年限 | |
| 857 | - func calculateWorkExperience(fromDateString: String) -> Int? { | |
| 863 | + let municipalities = Set(["北京市", "上海市", "天津市", "重庆市", "香港特别行政区", "澳门特别行政区"]) | |
| 864 | + func extractProvinceOrMunicipalityFromAddress(address: String) -> String? { | |
| 865 | + for zhixia in municipalities {//直辖市 | |
| 866 | + if address.contains(zhixia){ | |
| 867 | + return zhixia | |
| 868 | + } | |
| 869 | + } | |
| 870 | + //省 | |
| 871 | + let components = address.components(separatedBy: "省") | |
| 872 | + if components.count > 0{ | |
| 873 | + var retSheng = "" | |
| 874 | + if let shengStr = components.first{ | |
| 875 | + retSheng = shengStr+"省" | |
| 876 | + return retSheng | |
| 877 | + }else{ | |
| 878 | + return "" | |
| 879 | + } | |
| 880 | + }else{ | |
| 881 | + return "" | |
| 882 | + } | |
| 883 | + } | |
| 884 | + //计算工作年限 "2023.07.03" | |
| 885 | + func calculateWorkExperience(fromDateString: String) -> String { | |
| 858 | 886 | let formatter = DateFormatter() |
| 859 | 887 | formatter.dateFormat = "yyyy-MM-dd" |
| 860 | 888 | formatter.timeZone = TimeZone(abbreviation: "UTC")! // 确保时区一致,或者根据需要调整 |
| 861 | 889 | |
| 862 | 890 | guard let startDate = formatter.date(from: fromDateString) else { |
| 863 | - return nil | |
| 891 | + return "" | |
| 864 | 892 | } |
| 865 | 893 | |
| 866 | 894 | let calendar = Calendar.current |
| 867 | 895 | let currentDate = Date() |
| 868 | 896 | |
| 869 | 897 | // 计算年份差,这里我们不需要精确的月份和日期,所以只需要年份组件 |
| 870 | - let components = calendar.dateComponents([.year], from: startDate, to: currentDate) | |
| 871 | - guard let yearDifference = components.year else { | |
| 872 | - return nil | |
| 898 | + let components = calendar.dateComponents([.year, .month], from: startDate, to: currentDate) | |
| 899 | + // 提取年和月 | |
| 900 | + let years = components.year ?? 0 | |
| 901 | + let months = components.month ?? 0 | |
| 902 | + | |
| 903 | + // 格式化输出 | |
| 904 | + if years > 0 { | |
| 905 | + return "\(years)年经验" | |
| 906 | + } else if months > 0 { | |
| 907 | + return "\(months)个月经验" | |
| 908 | + } else { | |
| 909 | + return "0个月经验" | |
| 873 | 910 | } |
| 874 | - | |
| 875 | - // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 876 | - // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 877 | - let roundedYearDifference = round(Double(yearDifference)) | |
| 878 | - | |
| 879 | - // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 880 | - return Int(roundedYearDifference) | |
| 911 | + | |
| 912 | +// // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 913 | +// // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 914 | +// let roundedYearDifference = round(Double(yearDifference)) | |
| 915 | +// | |
| 916 | +// // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 917 | +// return Int(roundedYearDifference) | |
| 881 | 918 | } |
| 882 | 919 | |
| 883 | 920 | } | ... | ... |
metaCode/Classes/Main/HomePage/View/DigitalAuthViews/我的简历cell/CNLiveDigitalResumePreViewFirCell.swift
| ... | ... | @@ -265,7 +265,13 @@ class CNLiveDigitalResumePreViewFirCell: UITableViewCell { |
| 265 | 265 | self.hangyeTitleLabel.text = model.vitae?.profession |
| 266 | 266 | } |
| 267 | 267 | if model.vitae?.city.count ?? 0 > 0 && model.vitae?.showAddress == true{ |
| 268 | - self.weizhiTitleLabel.text = " | "+model.vitae!.city | |
| 268 | + let shengStr = self.extractProvinceOrMunicipalityFromAddress(address: model.vitae!.city) | |
| 269 | + if shengStr?.count ?? 0 > 0{ | |
| 270 | + self.weizhiTitleLabel.text = " | "+shengStr! | |
| 271 | + }else{ | |
| 272 | + self.weizhiTitleLabel.text = " | "+(shengStr ?? "") | |
| 273 | + } | |
| 274 | +// self.weizhiTitleLabel.text = " | "+model.vitae!.city | |
| 269 | 275 | }else{ |
| 270 | 276 | self.weizhiTitleLabel.text = " | 位置未授权" |
| 271 | 277 | } |
| ... | ... | @@ -285,11 +291,12 @@ class CNLiveDigitalResumePreViewFirCell: UITableViewCell { |
| 285 | 291 | workTimeStr = model.vitae!.workTime |
| 286 | 292 | } |
| 287 | 293 | |
| 288 | - if let workExperience = self.calculateWorkExperience(fromDateString: workTimeStr){ | |
| 289 | - yearStr = "\(workExperience)年经验" | |
| 290 | - }else{ | |
| 291 | - yearStr = "" | |
| 292 | - } | |
| 294 | + yearStr = self.calculateWorkExperience(fromDateString: workTimeStr) | |
| 295 | +// if let workExperience = self.calculateWorkExperience(fromDateString: workTimeStr){ | |
| 296 | +// yearStr = "\(workExperience)年经验" | |
| 297 | +// }else{ | |
| 298 | +// yearStr = "" | |
| 299 | +// } | |
| 293 | 300 | |
| 294 | 301 | self.workTitleLabel.text = yearStr//model.vitae!.workTime |
| 295 | 302 | |
| ... | ... | @@ -298,32 +305,90 @@ class CNLiveDigitalResumePreViewFirCell: UITableViewCell { |
| 298 | 305 | } |
| 299 | 306 | |
| 300 | 307 | } |
| 301 | - //计算工作年限 | |
| 302 | - func calculateWorkExperience(fromDateString: String) -> Int? { | |
| 308 | + let municipalities = Set(["北京市", "上海市", "天津市", "重庆市", "香港特别行政区", "澳门特别行政区"]) | |
| 309 | + func extractProvinceOrMunicipalityFromAddress(address: String) -> String? { | |
| 310 | + for zhixia in municipalities {//直辖市 | |
| 311 | + if address.contains(zhixia){ | |
| 312 | + return zhixia | |
| 313 | + } | |
| 314 | + } | |
| 315 | + //省 | |
| 316 | + let components = address.components(separatedBy: "省") | |
| 317 | + if components.count > 0{ | |
| 318 | + var retSheng = "" | |
| 319 | + if let shengStr = components.first{ | |
| 320 | + retSheng = shengStr+"省" | |
| 321 | + return retSheng | |
| 322 | + }else{ | |
| 323 | + return "" | |
| 324 | + } | |
| 325 | + }else{ | |
| 326 | + return "" | |
| 327 | + } | |
| 328 | + } | |
| 329 | + | |
| 330 | + //计算工作年限 "2023.07.03" | |
| 331 | + func calculateWorkExperience(fromDateString: String) -> String { | |
| 303 | 332 | let formatter = DateFormatter() |
| 304 | 333 | formatter.dateFormat = "yyyy-MM-dd" |
| 305 | 334 | formatter.timeZone = TimeZone(abbreviation: "UTC")! // 确保时区一致,或者根据需要调整 |
| 306 | 335 | |
| 307 | 336 | guard let startDate = formatter.date(from: fromDateString) else { |
| 308 | - return nil | |
| 337 | + return "" | |
| 309 | 338 | } |
| 310 | 339 | |
| 311 | 340 | let calendar = Calendar.current |
| 312 | 341 | let currentDate = Date() |
| 313 | 342 | |
| 314 | 343 | // 计算年份差,这里我们不需要精确的月份和日期,所以只需要年份组件 |
| 315 | - let components = calendar.dateComponents([.year], from: startDate, to: currentDate) | |
| 316 | - guard let yearDifference = components.year else { | |
| 317 | - return nil | |
| 344 | + let components = calendar.dateComponents([.year, .month], from: startDate, to: currentDate) | |
| 345 | + // 提取年和月 | |
| 346 | + let years = components.year ?? 0 | |
| 347 | + let months = components.month ?? 0 | |
| 348 | + | |
| 349 | + // 格式化输出 | |
| 350 | + if years > 0 { | |
| 351 | + return "\(years)年经验" | |
| 352 | + } else if months > 0 { | |
| 353 | + return "\(months)个月经验" | |
| 354 | + } else { | |
| 355 | + return "0个月经验" | |
| 318 | 356 | } |
| 319 | - | |
| 320 | - // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 321 | - // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 322 | - let roundedYearDifference = round(Double(yearDifference)) | |
| 323 | - | |
| 324 | - // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 325 | - return Int(roundedYearDifference) | |
| 357 | + | |
| 358 | +// // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 359 | +// // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 360 | +// let roundedYearDifference = round(Double(yearDifference)) | |
| 361 | +// | |
| 362 | +// // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 363 | +// return Int(roundedYearDifference) | |
| 326 | 364 | } |
| 365 | + | |
| 366 | +// //计算工作年限 | |
| 367 | +// func calculateWorkExperience(fromDateString: String) -> Int? { | |
| 368 | +// let formatter = DateFormatter() | |
| 369 | +// formatter.dateFormat = "yyyy-MM-dd" | |
| 370 | +// formatter.timeZone = TimeZone(abbreviation: "UTC")! // 确保时区一致,或者根据需要调整 | |
| 371 | +// | |
| 372 | +// guard let startDate = formatter.date(from: fromDateString) else { | |
| 373 | +// return nil | |
| 374 | +// } | |
| 375 | +// | |
| 376 | +// let calendar = Calendar.current | |
| 377 | +// let currentDate = Date() | |
| 378 | +// | |
| 379 | +// // 计算年份差,这里我们不需要精确的月份和日期,所以只需要年份组件 | |
| 380 | +// let components = calendar.dateComponents([.year], from: startDate, to: currentDate) | |
| 381 | +// guard let yearDifference = components.year else { | |
| 382 | +// return nil | |
| 383 | +// } | |
| 384 | +// | |
| 385 | +// // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 386 | +// // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 387 | +// let roundedYearDifference = round(Double(yearDifference)) | |
| 388 | +// | |
| 389 | +// // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 390 | +// return Int(roundedYearDifference) | |
| 391 | +// } | |
| 327 | 392 | func convertTimestampStringToDateString(timestampString: String) -> String? { |
| 328 | 393 | // 首先,将毫秒时间戳字符串转换为TimeInterval(秒) |
| 329 | 394 | guard let timestampMilliseconds = Double(timestampString) else { | ... | ... |