动手操作第一版本 而为了实现这个业务需要涉及三张表的数据

时间:2022-03-06 08:18:59

作为一名新手,一直没有勇气去写一篇分享。原因有很多:诸如:本身程度有限、语言表达禁绝确、写出的对象没有一点技术点被人讥笑。今天在公司听了内部员工的一个分享,此中最重要的一点是:提升自身程度的最佳的途径就是――交流。不管你是通过什么途径,交流也好、整理成文字分享也好等等都是很好的方法。故此,今天献丑写一篇本身的心得分享,欢迎各路大神的指教!


需求配景

今天接到的需求里面有个这样的需求,如下图所示,需要打印出如Excel内容泛起的单子。


动手操纵初版本

而为了实现这个业务需要涉及三张表的数据。(存放单子的表、审核定见表、审核状态表)

三张表的关系:单子表1:1审核状态表,单子表1:N审核定见表

为了实现让View页面整洁,,我界说了一个SpecialPrintModel类

public class SpecialPrintModel { /// <summary> /// 提供商承当 /// </summary> public string SupplierUnderTaker { get; set; } /// <summary> /// 客户订单号 /// </summary> public string CustomerSerialNumber { get; set; } /// <summary> /// 付款金额 /// </summary> public decimal PayAmount { get; set; } /// <summary> /// 开户行 /// </summary> public string OpeningBank { get; set; } /// <summary> /// 收款单位 /// </summary> public string CollectionMonad { get; set; } /// <summary> /// 银行帐号 /// </summary> public string BankAccount { get; set; } /// <summary> /// 经办人 /// </summary> public string ResponseiblePerson { get; set; } /// <summary> /// 分管带领 /// </summary> public string Leader { get; set; } /// <summary> /// 财务审核 /// </summary> public string FinanceApproval { get; set; } /// <summary> /// 财务经理审核 /// </summary> public string FinanceManagerApproval { get; set; } /// <summary> /// 财务总监审核 /// </summary> public string FinanceDirectorApproval { get; set; } /// <summary> /// CEO审核 /// </summary> public string CEOApproval { get; set; } /// <summary> /// 流水号 /// </summary> public string SerialNumber { get; set; } }

public List<ShipSpecialPrintModel> GetTobePaidRecepit(ShipSpecialSearch search) { List<ShipSpecialPrintModel> curiseShipModel = new List<ShipSpecialPrintModel>(); var toBePaidModel = persistant.GetTobePaidRecepit(search);//查找出待付出的单子表信息 ArrayList serialArray=new ArrayList();//界说一个流水号列表 toBePaidModel.ForEach((u) => { serialArr.Add(u.SerialNumber); }); var toBePaidComment = persistant.GetTobePaidRecepitComment(serialArr);//查找出待付出单子的审核定见表(1个单子对应几多审核定见) foreach (var item in toBePaidModel) { ShipSpecialPrintModel temp = new ShipSpecialPrintModel() { SupplierUnderTaker = supplierUnderTaker; CustomerSerialNumber = item.CustomerOrderNumber; PayAmount = item.PayAmount; OpeningBank = item.PayBank; CollectionMonad = item.Payee; ResponseiblePerson = item.Creator; SerialNumber = item.SerialNumber; }; curiseShipModel.Add(temp); } foreach (var curise in curiseShipModel) { foreach (var comment in toBePaidComment) { if (comment.SerialNumber == curise.SerialNumber) { if (comment.ApprovalLevel == (int)LevelType.BranchedLeader) { curise.Leader = comment.Creator; } else if (comment.ApprovalLevel == (int)LevelType.Finance) { curise.FinanceApproval = comment.Creator; } else if (comment.ApprovalLevel == (int)LevelType.FinanceManager) { curise.FinanceManagerApproval = comment.Creator; } else if (comment.ApprovalLevel == (int)LevelType.ProjectDirector) { curise.FinanceDirectorApproval = comment.Creator; } else if (comment.ApprovalLevel == (int)LevelType.CEO) { curise.CEOApproval = comment.Creator; } } } } return curiseShipModel }

呵呵,上面的代码根基完成了业务的需求,可是如果业务需要打印出CTO的名称、CIO的名称那在if else这边加,虽然很简单但是违背了开放-关闭的原则。故本人决定用反射去完成这if…else的工作。

因为if…else里面的判断是当前的这笔单子的审核定见表的层级是不是跟SpecialPrintModel的字段所对应的层级相等,若相等则在对应字段写入相对应的名称。决定把SpecialPrintModel这个类改削下。


动手操纵第二版本

public class ShipSpecialPrintModel { /// <summary> /// 提供商承当 /// </summary> public string SupplierUnderTaker { get; set; } /// <summary> /// 客户订单号 /// </summary> public string CustomerSerialNumber { get; set; } /// <summary> /// 付款金额 /// </summary> public decimal PayAmount { get; set; } /// <summary> /// 开户行 /// </summary> public string OpeningBank { get; set; } /// <summary> /// 收款单位 /// </summary> public string CollectionMonad { get; set; } /// <summary> /// 银行帐号 /// </summary> public string BankAccount { get; set; } /// <summary> /// 经办人 /// </summary> public string ResponseiblePerson { get; set; } /// <summary> /// 分管带领 /// </summary> [LevelAttribute(Level = 1)] public string Leader { get; set; } /// <summary> /// 财务审核 /// </summary> [LevelAttribute(Level = 2)] public string FinanceApproval { get; set; } /// <summary> /// 财务经理审核 /// </summary> [LevelAttribute(Level = 3)] public string FinanceManagerApproval { get; set; } /// <summary> /// 财务总监审核 /// </summary> [LevelAttribute(Level = 4)] public string FinanceDirectorApproval { get; set; } /// <summary> /// CEO审核 /// </summary> [LevelAttribute(Level = 5)] public string CEOApproval { get; set; } /// <summary> /// 流水号 /// </summary> public string SerialNumber { get; set; } } public class LevelAttribute : Attribute { public int Level { get; set; } }