Commit 7e4fc3febff3c57eff0352050daea1a0c5dea283
1 parent
8526ab7c
* [x] 保存简历接口 UI显示'2024-07-27(1个月经验)',workTime传'2024-07-27' , 数字简历页面查简历时再把2024-07-27转换为x年经验
Showing
2 changed files
with
52 additions
and
6 deletions
metaCode/Classes/Main/HomePage/Controller/DigitalAuth/数字简历相关页面/CNLiveDigitalResumeInfoController.swift
| ... | ... | @@ -378,9 +378,17 @@ class CNLiveDigitalResumeInfoController:CNLiveBaseViewController, UITextFieldDel |
| 378 | 378 | } |
| 379 | 379 | func loadLocalData(){ |
| 380 | 380 | if var userDic = UserDefaults.standard.dictionary(forKey: UserInfoManager.shared.userInfo.uid){ |
| 381 | - if let seleDay = userDic["jianli_workTime"]{ | |
| 381 | + if let seDay = userDic["jianli_workTime"]{ | |
| 382 | 382 | //设置过工作日期 |
| 383 | - self.canjiaRightTitleLabel.text = seleDay as? String | |
| 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 | + } | |
| 390 | + | |
| 391 | + self.canjiaRightTitleLabel.text = yearStr | |
| 384 | 392 | }else{ |
| 385 | 393 | //没设置过工作日期 |
| 386 | 394 | self.canjiaRightTitleLabel.text = "请选择" |
| ... | ... | @@ -600,16 +608,18 @@ class CNLiveDigitalResumeInfoController:CNLiveBaseViewController, UITextFieldDel |
| 600 | 608 | if (text as! String).count > 0{ |
| 601 | 609 | var yearStr = "" |
| 602 | 610 | if let textStr = text as? String{ |
| 611 | + | |
| 612 | + var yearStr = "" | |
| 603 | 613 | if let workExperience = self?.calculateWorkExperience(fromDateString: textStr){ |
| 604 | - yearStr = "\(workExperience)年经验" | |
| 614 | + yearStr = "\(textStr)(\(workExperience)年经验)" | |
| 605 | 615 | }else{ |
| 606 | - yearStr = "请选择" | |
| 616 | + yearStr = textStr | |
| 607 | 617 | } |
| 618 | + yearStr = textStr | |
| 608 | 619 | }else{ |
| 609 | 620 | yearStr = "请选择" |
| 610 | 621 | } |
| 611 | 622 | |
| 612 | - | |
| 613 | 623 | self?.canjiaRightTitleLabel.text = yearStr |
| 614 | 624 | self?.canjiaRightTitleLabel.textColor = HexColor("#333333") |
| 615 | 625 | ... | ... |
metaCode/Classes/Main/HomePage/View/DigitalAuthViews/DigitalResume/CNLiveDigitalResumeCell.swift
| ... | ... | @@ -822,7 +822,15 @@ class CNLiveDigitalResumeCell: UITableViewCell { |
| 822 | 822 | self.weizhiTitleLabel.text = ""//" | 位置未授权" |
| 823 | 823 | } |
| 824 | 824 | if model.vitae?.workTime.count ?? 0 > 0{ |
| 825 | - self.workTitleLabel.text = model.vitae!.workTime | |
| 825 | + var yearStr = "" | |
| 826 | + if let workExperience = self.calculateWorkExperience(fromDateString: model.vitae!.workTime){ | |
| 827 | + yearStr = "\(workExperience)年经验" | |
| 828 | + }else{ | |
| 829 | + yearStr = "" | |
| 830 | + } | |
| 831 | + | |
| 832 | + self.workTitleLabel.text = yearStr//model.vitae!.workTime | |
| 833 | + | |
| 826 | 834 | }else{ |
| 827 | 835 | self.workTitleLabel.text = "参加工作时间未设置 >" |
| 828 | 836 | } |
| ... | ... | @@ -836,4 +844,32 @@ class CNLiveDigitalResumeCell: UITableViewCell { |
| 836 | 844 | self.gongzuoDetailNumberTitleLabel.text = "\(model.works.count)" |
| 837 | 845 | self.huojiangDetailNumberTitleLabel.text = "\(model.awards.count)" |
| 838 | 846 | } |
| 847 | + | |
| 848 | + //计算工作年限 | |
| 849 | + func calculateWorkExperience(fromDateString: String) -> Int? { | |
| 850 | + let formatter = DateFormatter() | |
| 851 | + formatter.dateFormat = "yyyy-MM-dd" | |
| 852 | + formatter.timeZone = TimeZone(abbreviation: "UTC")! // 确保时区一致,或者根据需要调整 | |
| 853 | + | |
| 854 | + guard let startDate = formatter.date(from: fromDateString) else { | |
| 855 | + return nil | |
| 856 | + } | |
| 857 | + | |
| 858 | + let calendar = Calendar.current | |
| 859 | + let currentDate = Date() | |
| 860 | + | |
| 861 | + // 计算年份差,这里我们不需要精确的月份和日期,所以只需要年份组件 | |
| 862 | + let components = calendar.dateComponents([.year], from: startDate, to: currentDate) | |
| 863 | + guard let yearDifference = components.year else { | |
| 864 | + return nil | |
| 865 | + } | |
| 866 | + | |
| 867 | + // 如果需要,可以对年份差进行四舍五入(但在这个场景下,由于我们只计算整年,所以四舍五入可能不是必需的) | |
| 868 | + // 但为了完整性,我还是展示了如何四舍五入到最近的整数 | |
| 869 | + let roundedYearDifference = round(Double(yearDifference)) | |
| 870 | + | |
| 871 | + // 返回工作经验年数(已经是整数了,因为round函数的结果会被隐式转换为Int) | |
| 872 | + return Int(roundedYearDifference) | |
| 873 | + } | |
| 874 | + | |
| 839 | 875 | } | ... | ... |