替代料

那么好的日子不写代码不肝博客岂不是浪费生命。关于bom做过erp的小伙伴应该都清楚,那么关于替代料应该也都知道,就是当某一个物料供应方没货源后我们的生产不至于因为没原料而停滞不前。于是我们做的erp也是增加了替代料的功能。
有不理解的小朋友先看一下效果图吧:

这张图片就是我们的bom列表,点击编辑之后显示的就是这条bom的信息和它的组成物料表,如下图:

这张图片上面展示的就是这条bom的信息,下面展示的就是组成这个产品的原料表,点击替代后效果和这张图是一奶同胞的效果,只不过上面展示的是这条物料的信息,下面展示的是它的可替代料表。

有图片作参考是不是就清晰很多了,那么接下来我们来说一下原理。

功能实现及原理

因为这是半成品的bom,在定义上还不属于成熟的成品,所以是和物料同放进物料表的,我们要做的就是在数据库里面新增一张关系表,里面要有bom的id,物料的id,替代料的id这三个id是必不可少的。
那么接下来说一下功能的实现,首先是第一张图片的实现,无外乎是一个查询,连表查询一下bom的关系表和物料表,代码粘一下就不具体解释了。

  public async Task<Result<PageApi<ProductionDto>>> GetProductionData(BOMSearchDto model){RefAsync<int> totalCount = 0;var key = model.Key?.Trim();try{// SQL invar dbResult = await Db.Queryable<MaterialModel, PublicUnits>((f, a) => new JoinQueryInfos(JoinType.Left, f.PublicUnitsId == a.Id)).Where(f => SqlFunc.Subqueryable<SemiProductionBom>().Where(s => s.ProductionId == f.Id).Any()).WhereIF(!string.IsNullOrWhiteSpace(key), f => f.Encode.Contains(key) || f.Name.Contains(key) || f.Description.Contains(key)).Select((f, a) => new ProductionDto{ProductionId = f.Id,ProductionCode = f.Encode,ProductionName = f.Name,ProductionDesc = f.Description,ProductionUintSymbol = a.Symbol}).ToPageListAsync(model.Page, model.Limit, totalCount);return Result<PageApi<ProductionDto>>.IsSuccess(new PageApi<ProductionDto>{Items = dbResult,Total = totalCount});}catch (Exception ex){return Result<PageApi<ProductionDto>>.IsError(ex);}}

只粘了一个service里的实现代码,控制器的代码就不粘了,比较简单。主要是通过连表查询来显示出来bom的信息。加下来是点击编辑进入这条bom下物料的信息。

public async Task<Result<ProductionDto>> GetProductionDataById(int productionId = 0){if (productionId <= 0){return Result<ProductionDto>.IsFailed(message: "请输入有效id!");}var dbResult = await Db.Queryable<MaterialModel, PublicUnits>((f, a) => new JoinQueryInfos(JoinType.Left, f.PublicUnitsId == a.Id)).Where(f => f.Id.Equals(productionId)).Select((f, a) => new ProductionDto{ProductionId = f.Id,ProductionCode = f.Encode,ProductionName = f.Name,ProductionDesc = f.Description,ProductionUintSymbol = a.Symbol}).FirstAsync();if (dbResult == null){return Result<ProductionDto>.IsFailed(message: "未查询到数据!");}return Result<ProductionDto>.IsSuccess(dbResult);}

通过传递过来的id进行查询来实现上半部分的功能,这点应该是比较简单的。

在视图里面我们获取这条物料的id,然后作为条件传递给红圈选中的方法。

 public async Task<Result<PageApi<ProductionBOMDto>>> GetProductionBOMData(BOMSearchDto model){RefAsync<int> totalCount = 0;try{// SQL invar dbResult = await Db.Queryable<SemiProductionBom, MaterialModel, PublicUnits>((f, a, b) => new JoinQueryInfos(JoinType.Left, f.MaterialId == a.Id,JoinType.Left, a.PublicUnitsId == b.Id)).Where(f => f.ProductionId == model.ProductionId).Select((f, a, b) => new ProductionBOMDto{Id = f.Id,MaterialId=a.Id,MaterialCode = a.Encode,MaterialName = a.Name,MaterialDesc = a.Description,MaterialUintSymbol = b.Symbol,MaterialUsage = f.MaterialUsage,Base = f.Base,MaterialType = f.MaterialType}).ToPageListAsync(model.Page, model.Limit, totalCount);return Result<PageApi<ProductionBOMDto>>.IsSuccess(new PageApi<ProductionBOMDto>{Items = dbResult,Total = totalCount});}catch (Exception ex){return Result<PageApi<ProductionBOMDto>>.IsError(ex);}}

这样做我们可以查到他下面的组成原料的所有信息,点击替代的时候有一点需要注意的是上面部分既要显示所选的这条物料的信息,还要显示出来它的上一级bom名字。

[HttpGet][Display(Name = "视图_半成品BOM物料替代")]public async Task<IActionResult> SemiProductionBOMEditMaterial2(int Id = 0){var dbResult = await _productionBOMService.GetProductionMaterialDataById(Id);Id = dbResult.Data.ProductionId;ViewBag.IsName = await _productionBOMService.GetProductionMaterialDataById2(Id);if (!dbResult.Success){return Json(ResultApi<ProductionBOMDto>.Result(dbResult));}return View(dbResult.Data);}

这样的话我们可以得到bom的id,那么我们需要在service里面在写一个通过bom的id来查询名字的方法,这样就实现了页面上即有原料的信息也有bom的名字。
接下来是查询下面的替代料信息。

public async Task<Result<PageApi<ProductionSubstituteDto>>> GetProductionBOMData2(SearchDto model,int materialId = 0,int productionId = 0){RefAsync<int> totalCount = 0;try{// SQL invar dbResult = await Db.Queryable<MaterialModel, PublicUnits, MaterialSubstitute>((f, a, b) => new JoinQueryInfos(JoinType.Left, f.PublicUnitsId == a.Id,JoinType.Left, f.Id==b.TiDaiId)).Where(f => SqlFunc.Subqueryable<MaterialSubstitute>().Where(s => s.BomId == productionId&&s.YuanLiaoId==materialId&&s.TiDaiId==f.Id).Any()).Select((f, a, b) => new ProductionSubstituteDto{Id = b.Id,ProductionSubstituteCode = f.Encode,ProductionSubstituteName = f.Name,ProductionSubstituteDesc = f.Description,ProductionSubstituteSymbol = a.Symbol,ProductionSubstituteXuHao = b.XuHao}).ToPageListAsync(model.Page, model.Limit, totalCount);//var dbResult = await Db.Queryable<MaterialSubstitute, SemiProductionBom, MaterialModel, PublicUnits>((f, a, b, c) => new JoinQueryInfos(//   JoinType.Left, f.BomId == a.Id,//   JoinType.Left, f.YuanLiaoId == b.Id,//   JoinType.Left, b.PublicUnitsId == c.Id//  ))//  .Where((f, a, b, c) => f.BomId == productionId && f.YuanLiaoId == materialId)//    .Select((f, a, b, c) => new ProductionSubstituteDto//    {//        Id = f.Id,//        ProductionSubstituteCode = b.Encode,//        ProductionSubstituteName = b.Name,//        ProductionSubstituteDesc = b.Description,//        ProductionSubstituteSymbol = c.Symbol,//        ProductionSubstituteXuHao = f.XuHao//    })                    //.ToPageListAsync(model.Page, model.Limit, totalCount);//sql in//var dbResult = Db.Queryable<MaterialModel>().Where(it =>SqlFunc.Subqueryable<MaterialSubstitute>().Where(s => s.TiDaiId == it.Id).Any()).ToList();//原生SQL//var dbResult = Db.Ado.GetDataTable("select * from mtt_Material_Model where TypeId in(select TiDaiId from mtt_Material_Substitute where BomId=@bomid and YuanLiaoId=@yuanliaoid)", new { bomid = productionId, yuanliaoid = materialId });//var Sqlmate = "select * from mtt_Material_Model where TypeId in(select TiDaiId from mtt_Material_Substitute where BomId='" + productionId + "'and YuanLiaoId='" + materialId + "')";//var dbResult = Db.Ado.GetDataTable(Sqlmate);//List<ProductionSubstituteDto> ps = new List<ProductionSubstituteDto>();//ps = ConvertReToList(dbResult);return Result<PageApi<ProductionSubstituteDto>>.IsSuccess(new PageApi<ProductionSubstituteDto>{Items = dbResult,Total = totalCount});}catch (Exception ex){return Result<PageApi<ProductionSubstituteDto>>.IsError(ex);}}

这就用到了SQLSugar中的SQL in用法。代码中也有原生SQL语句,所以我们可以清晰的看出,我们是通过传过来的bom的id和原料的id来去关系表中查替代料的id,然后在拿我们查询到的id去物料表中查询相对应的信息。
这样页面上能看到的功能就可以实现了,还有增加修改就不细说了,但是需要注意一点的就是当你的替代料进行增加和修改的时候,一定不要忘了传bom的id还有物料的id。

切记!!!

兄弟们切记写代码一定要养成一个良好的代码习惯。
第一,一定要写注释;
第二,一定要规范命名。
如果两者都没遵循的话,你会发现你的代码不光乱到别人看不懂,你自己也看不懂。
一定要写注释,写注释,写注释!!!

ERP中Bom的替代料相关推荐

  1. ERP中BOM的数据库设计与实现

    引言在企业资源计划(Enterprise Resource Planning,ERP)中, 物料清单(Bill of Materials,BOM)是系统中的最基本资料,用来描述产品的零部件组成和零部件 ...

  2. ERP中BOM变更操作的简单操作

    BOM变更 BOM变更在ERP中时不时的会发生,BOM变更不仅仅是只是BOM版本变更一下就结束了,往往旧版本的BOM相关正在生产中的工单如何处理才是最重要,也是最麻烦的事情. 生产过程节点这张图进行理 ...

  3. 企业在ERP实施中BOM管理的常见问题

    BOM(物料清单)是ERP系统软件最为关键的名词,对BOM的定义层次和数据准备的精确程度,直接影响专业中小企业ERP系统软件的整体运行状况.所以,稳定和准确BOM数据是每个ERP系统软件实施极为关键的 ...

  4. erp中三大订单CO、PO、MO各是代表什么?

    ERP即 企业资源计划 (Enterprise Resource Planning),由美国 Gartner Group 公司于1990年提出. ERP系统是指建立在信息技术基础上,以系统化的管理思想 ...

  5. ERP中的制造数据结构

    一.制造数据结构的概念     制造数据结构(Manufacturing Data Structures)是表达和组织制造对象及其制造过程的信息体系.在制造业信息化中,制造数据结构是一个最基本的概念. ...

  6. ERP中物料删除与停用

    ERP中总会存在一些错误或者重复的物料代码,对于这种情况,处理办法就是:删除或者停用掉.(以下仅代表个人实际经验,也佩服大神直接后台直接操作) 基本操作 如何去判断一个错误的物料是删除掉还是停用掉的呢 ...

  7. ERP中的合并会计报表

    随着企业集团的发展,集团内部会出现越来越多的公司:复杂的公司结构和复杂的集团内业务,使得集团内部管理困难重重,信息渠道严重失灵.除了内部管理的需要,企业还有义务向相关方提供详细的和及时的信息.ERP中 ...

  8. php 头bom_关于php中bom头的简介

    关于php中bom头的简介 发布时间:2020-06-30 17:48:12 来源:亿速云 阅读:99 作者:清晨 这篇文章主要介绍关于php中bom头的简介,文中示例代码介绍的非常详细,具有一定的参 ...

  9. PLM中BOM核心技术的研究[转]

       作者:曾富洪  频道:机床  发布时间:2007-09-30 21 世纪的市场机制是以消费者为向导的市场机制,也就是说:企业的产品必须是满足消费者不断变化的需求的产品.消费者的需求通常包含5 个 ...

最新文章

  1. iOS UICollectionView实现瀑布流(3)
  2. apache负载均衡的安装和实现方法
  3. MySQL8.0: Serialized Dictionary Information(SDI) 浅析
  4. 使用此首选项可加快Eclipse m2e配置
  5. AD域控exchange邮箱(一)——批量安装MSI安装包
  6. Linux系统下如何设置IP地址?
  7. 用c语言小游戏代码大全,c语言经典游戏代码
  8. python处理xps文件_WFP: 读取XPS文件或将word、txt文件转化为XPS文件
  9. 【转载】我的考试生涯:一个“放牛班”学生的逆袭
  10. 解决 VMware 无法复制粘贴问题
  11. 陕西师范大学第七届程序设计竞赛网络同步赛 - ZQ的睡前故事 -(三种方法)
  12. matlab中zi filtic b a,实验七离散系统分析的matlab实现.doc_蚂蚁文库
  13. QQ Tim另存为文件时闪退,错误模块ntdll.dll
  14. Document-Level Relation Extraction with Adaptive Thresholding and Localized Context Pooling
  15. springboot整合websocket异常集合
  16. 自动调制分类发展历程
  17. nodejs mysql更新redis_node中的redis使用--ioredis
  18. Cannot read lifecycle mapping metadata for artifact org.apache.maven.plugins:mav问题
  19. 【Linux】Linux 基础开发工具(yum、vim、gcc/g++、gdb、make/makefile、git)
  20. 20款可嵌入网站和博客的免费音频播放器

热门文章

  1. 软件测试的定义是什么?
  2. MTK芯片技术资料大全,各个型号都有,包括原理图数据表等
  3. 杨贵妃深受日本人喜爱 供奉为“热田大明神”
  4. 大地水准面 地球椭球体 大地基准面 地图投影理解
  5. hibernate: 用Disjunction和Conjunction构造复杂的查询条件
  6. sata port multiplier
  7. JAVA经典算法大全
  8. ngro_k服务器搭建(本地电脑与微信交互)
  9. Typecho权限管理插件 - 权限狗
  10. mysql 1033 frm_修复mysqldump Incorrect information in file frm (1033)