NewRepairItemModel.m 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // NewRepairItemModel.m
  3. // IBOSS
  4. //
  5. // Created by apple on 16/1/19.
  6. // Copyright © 2017年 沈阳东科云信软件有限公司. All rights reserved.
  7. //
  8. // 功能描述:新增维修模型
  9. #import "NewRepairItemModel.h"
  10. @implementation NewRepairItemModel
  11. #pragma 私有函数
  12. /*!
  13. * 1.该方法是 `字典里的属性Key` 和 `要转化为模型里的属性名` 不一样 而重写的
  14. * 前:模型的属性 后:字典里的属性
  15. */
  16. + (nullable NSDictionary<NSString *, id> *)modelCustomPropertyMapper{
  17. return @{@"repairId":@"RepairID",
  18. @"detailId":@"DetailID",
  19. @"salesDetailId":@"SalesDetailID",
  20. @"code":@"Code",
  21. @"onlyCode":@"OnlyCode",
  22. @"brandName":@"BrandName",
  23. @"repairQuantity":@"RepairQuantity",
  24. @"returnQuantity":@"ReturnQuantity",
  25. @"completeQuantity":@"FinishQuantity",
  26. @"unitId":@"UnitID",
  27. @"unitName":@"UnitName",
  28. @"mm":@"M2",
  29. @"acreage":@"Acreage",
  30. @"package":@"Package",
  31. @"remarks":@"ReceiptRemarks",
  32. @"sourceFrom":@"SourceFrom"
  33. };
  34. }
  35. /*!
  36. * 2. 下面的两个方法 `字典里值`与`模型的值`类型不一样`需要转换`而重写的方法
  37. * NSDate *time dic[@"t"]是double类型的的秒数
  38. */
  39. - (BOOL)modelCustomTransformFromDictionary:(NSDictionary *)dic
  40. {
  41. int decimalPlaces = [[dic objectForKey:@"DecimalPlaces"] intValue];
  42. NSString *str = [NSString stringWithFormat:@"%@%d%@",@"%.",decimalPlaces,@"f"];
  43. self.repairId = [[dic objectForKey:@"RepairID"] stringValue];
  44. self.detailId = [[dic objectForKey:@"DetailID"] stringValue];
  45. self.salesDetailId = [[dic objectForKey:@"SalesDetailID"] stringValue];
  46. self.repairQuantity = [dic objectForKey:@"RepairQuantity"] == nil ? @"0":[NSString stringWithFormat:str,[[dic objectForKey:@"RepairQuantity"]doubleValue]];
  47. self.returnQuantity = [dic objectForKey:@"ReturnQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"ReturnQuantity"]doubleValue]];
  48. self.completeQuantity = [dic objectForKey:@"FinishQuantity"] == nil?@"0":[NSString stringWithFormat:str,[[dic objectForKey:@"FinishQuantity"]doubleValue]];
  49. self.mm = [[dic objectForKey:@"M2"]stringValue];
  50. self.acreage = [[dic objectForKey:@"Acreage"]stringValue];
  51. self.package = [[dic objectForKey:@"Package"]stringValue];
  52. if (self.package == nil|| [self.package isEqualToString:@""] || [self.package isEqualToString:@"0"]) {
  53. self.box = @"0";
  54. self.receiptQuantity = @"0";
  55. self.piece = @"0";
  56. }
  57. else{
  58. double quantity = [self.repairQuantity doubleValue]-[self.completeQuantity doubleValue];
  59. int result= (int)quantity%[self.package intValue];
  60. if (quantity == 0.0) {
  61. self.receiptQuantity = @"0";
  62. }else{
  63. self.receiptQuantity = [NSString stringWithFormat:str,quantity];
  64. }
  65. double box=floor(quantity/([self.package doubleValue]));
  66. if (box == 0.0) {
  67. self.box = @"0";
  68. }else{
  69. self.box = [NSString stringWithFormat:@"%f",box];
  70. }
  71. self.piece = [NSString stringWithFormat:@"%d",result];
  72. }
  73. return YES;
  74. }
  75. @end