U8生产订单API接口示例

1.json示例:

{
    "mom_order": {
        "ctradenum": "CD7DAD1D-AEF4-4E2F-B110-B30A0CEDFFA3",
        "caccid": "999",
        "imoid": "",
        "cmocode": "",
        "cverifier": "demo",
        "cmaker": "demo",
        "mom_orderdetail": [
            {
                "imodid": "",
                "cinvcode": "2.3291-M1010-0101",
                "iquantity": "100",
                "dstartdate": "2021-07-07",
                "dduedate": "2021-07-15",
                "imotypeid": "1000000001",
                "whcode": "01",
                "mdeptcode": "0201",
                "cmemo": "2021-07-15",
            }
        ]
    }
}

U8生产订单API接口示例_第1张图片

2.构造对应实体

U8生产订单API接口示例_第2张图片

实体内容大致如下

U8生产订单API接口示例_第3张图片

 

 接口实现3种方式

U8自带的api(调用麻烦还容易出问题但是可以确保数据一致性),

U8bo(生产模块使用的是BO,调用麻烦传递复杂生成效果可以),

直接插库(风险大回报高)

本案例使用直接插库示例如下:

生产订单涉及4个表

mom_order

mom_orderdetail

mom_morder(注意这张表)

mom_moallocate

接下来就是填字游戏 填好字段插入就行

示例

INSERT INTO dbo.mom_order
( MoId ,MoCode ,CreateDate ,CreateUser ,ModifyDate ,ModifyUser ,UpdCount ,
Define1 ,Define2 ,Define3 ,Define4 ,Define5 ,Define6 ,Define7 ,Define8 ,Define9 ,Define10 ,Define11 ,Define12 ,Define13 ,Define14 ,Define15 ,Define16 ,
VTid ,CreateTime ,ModifyTime ,iPrintCount ,RelsVTid ,cSysBarCode ) VALUES
 ( @MoId ,@MoCode ,convert(nvarchar(12),GETDATE(),23)  ,@CreateUser ,NULL ,NULL ,0 ,
@Define1 ,@Define2 ,@Define3 ,@Define4 ,@Define5 ,@Define6 ,@Define7 ,@Define8 ,@Define9 ,@Define10 ,@Define11 ,@Define12 ,@Define13 ,@Define14 ,@Define15 ,@Define16 ,
30413 ,GETDATE() ,NULL ,0 ,30422 ,@cSysBarCode )

INSERT INTO dbo.mom_orderdetail
( MoDId ,MoId ,SortSeq ,MoClass ,MoTypeId ,Qty ,MrpQty ,AuxUnitCode ,AuxQty ,ChangeRate ,MoLotCode ,WhCode ,MDeptCode ,SoType ,SoDId ,SoCode ,SoSeq ,DeclaredQty ,QualifiedInQty ,Status ,OrgStatus ,BomId ,RoutingId ,CustBomId ,DemandId ,PlanCode ,PartId ,
InvCode ,Free1 ,Free2 ,Free3 ,Free4 ,Free5 ,Free6 ,Free7 ,Free8 ,Free9 ,Free10 ,SfcFlag ,CrpFlag ,QcFlag ,RelsDate ,RelsUser ,CloseDate ,OrgClsDate ,
Define22 ,Define23 ,Define24 ,Define25 ,Define26 ,Define27 ,Define28 ,Define29 ,Define30 ,Define31 ,Define32 ,Define33 ,Define34 ,Define35 ,Define36 ,Define37 ,
LeadTime ,OpScheduleType ,OrdFlag ,WIPType ,SupplyWhCode ,ReasonCode ,IsWFControlled ,iVerifyState ,iReturnCount ,
Remark ,SourceMoCode ,SourceMoSeq ,SourceMoId ,SourceMoDId ,SourceQCCode ,SourceQCId ,SourceQCDId ,CostItemCode ,CostItemName ,
RelsTime ,CloseUser ,CloseTime ,OrgClsTime ,AuditStatus ,PAllocateId ,DemandCode ,
CollectiveFlag ,OrderType ,OrderDId ,OrderCode ,OrderSeq ,ManualCode ,ReformFlag ,SourceQCVouchType ,OrgQty ,FmFlag ,MinSN ,MaxSN ,
SourceSvcCode ,SourceSvcId ,SourceSvcDId ,BomType ,RoutingType ,BusFlowId ,RunCardFlag ,RequisitionFlag ,AlloVTid ,RelsAlloVTid ,iPrintCount ,cbSysBarCode ,cCurrentAuditor
)VALUES
( @MoDId ,@MoId ,@SortSeq ,@MoClass ,@MoTypeId ,@Qty ,@MrpQty ,@AuxUnitCode ,@AuxQty ,@ChangeRate ,@MoLotCode ,@WhCode ,@MDeptCode ,@SoType ,NULL ,NULL ,NULL ,0 ,0 ,2 ,2 ,@BomId ,@RoutingId ,0 ,0 ,NULL ,@PartId ,
@InvCode ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,NULL ,0 ,0 ,0 ,0 ,NULL ,NULL ,NULL ,
@Define22 ,@Define23 ,@Define24 ,@Define25 ,@Define26 ,@Define27 ,@Define28 ,@Define29 ,@Define30 ,@Define31 ,@Define32 ,@Define33 ,@Define34 ,@Define35 ,@Define36 ,@Define37 ,
0 ,3 ,0 ,5 ,NULL ,NULL ,0 ,0 ,0 ,
@Remark ,NULL ,NULL ,0 ,0 ,NULL ,0 ,0 ,NULL ,NULL ,
NULL ,NULL ,NULL ,NULL ,1 ,0 ,NULL ,0 ,0 ,0 ,NULL ,NULL ,NULL ,0 ,0 ,0 ,0 ,NULL ,NULL ,
NULL ,NULL ,NULL ,1 ,0 ,NULL ,0 ,0 ,30417 ,0 ,0 ,@cbSysBarCode ,NULL ) 

INSERT INTO dbo.mom_morder
( MoDId, StartDate, DueDate, MoId )VALUES  (@MoDId, @StartDate, @DueDate, @MoId)

子件会麻烦一点 参考文章获取bom的方法在插入子件


INSERT INTO dbo.mom_moallocate
( AllocateId ,MoDId ,SortSeq ,OpSeq ,ComponentId ,FVFlag ,BaseQtyN ,BaseQtyD ,ParentScrap ,CompScrap ,Qty ,IssQty ,DeclaredQty ,StartDemDate ,EndDemDate ,WhCode ,LotNo ,WIPType ,ByproductFlag ,QcFlag ,Offset ,
InvCode ,Free1 ,Free2 ,Free3 ,Free4 ,Free5 ,Free6 ,Free7 ,Free8 ,Free9 ,Free10 ,
OpComponentId ,Define22 ,Define23 ,Define24 ,Define25 ,Define26 ,Define27 ,Define28 ,Define29 ,Define30 ,Define31 ,Define32 ,Define33 ,Define34 ,Define35 ,Define36 ,Define37 ,
AuxUnitCode ,ChangeRate ,AuxBaseQtyN ,AuxQty ,ReplenishQty ,Remark ,TransQty ,ProductType ,SoType ,SoDId ,SoCode ,SoSeq ,DemandCode ,QmFlag ,OrgQty ,OrgAuxQty ,CostItemCode ,CostItemName ,
RequisitionFlag ,RequisitionQty ,RequisitionIssQty ,CostWIPRel ,MoallocateSubId ,cSubSysBarCode ,PickingQty ,PickingAuxQty ,UpperMoQty ,InvAlloeFlag )

SELECT ROW_NUMBER() over(order by b.OpComponentId )+{1} AS AllocateId,{2} AS MoDId, (ROW_NUMBER() over(order by b.OpComponentId) )*10 AS SortSeq,b.OpSeq,
d.PartId AS ComponentId,1 AS FVFlag,b.BaseQtyN ,b.BaseQtyD  ,c.ParentScrap,b.CompScrap,
{3}* (1 + b.CompScrap / 100) * b.BaseQtyN / b.BaseQtyD AS qty, 0 AS IssQty ,0 AS DeclaredQty ,GETDATE() AS StartDemDate ,GETDATE() AS EndDemDate ,opt.Whcode,NULL AS LotNo,opt.WIPType,b.ByproductFlag,0 AS QcFlag,opt.Offset,
f.cinvcode  AS InvCode,b.Free1 ,b.Free2 ,b.Free3 ,b.Free4 ,b.Free5 ,b.Free6 ,b.Free7 ,b.Free8 ,b.Free9 ,b.Free10 ,
b.OpComponentId,b.Define22 ,b.Define23 ,b.Define24 ,b.Define25 ,b.Define26 ,b.Define27 ,b.Define28 ,b.Define29 ,b.Define30 ,b.Define31 ,b.Define32 ,b.Define33 ,b.Define34 ,b.Define35 ,b.Define36 ,b.Define37 ,
c1.cComunitCode AS AuxUnitCode,c1.iChangRate AS ChangeRate,b.BaseQtyN /IIF(c1.iChangRate=0,NULL,c1.iChangRate) AS AuxBaseQtyN,
 {3} * (1 + b.CompScrap/ 100) * b.BaseQtyN / b.BaseQtyD / c1.iChangRate AS AuxQty,
 0 AS ReplenishQty,NULL AS Remark,0 AS TransQty,b.ProductType,0 AS SoType,0 AS SoDId,NULL AS SoCode ,NULL AS SoSeq ,NULL AS DemandCode ,0 AS QmFlag ,0 AS OrgQty ,0 AS OrgAuxQty ,NULL AS CostItemCode ,NULL AS CostItemName ,
 CASE WHEN isub.iDrawType=1 THEN 1 ELSE 0 END AS RequisitionFlag,0 AS RequisitionQty ,0 ASRequisitionIssQty ,0 AS CostWIPRel ,NULL AS MoallocateSubId ,
 '||MO21|{4}|1|'+ cast((ROW_NUMBER() over(order by b.OpComponentId) )*10 AS nvarchar(5))  AS cSubSysBarCode ,0 AS PickingQty ,0 AS PickingAuxQty ,
 {3} AS UpperMoQty ,0 AS InvAlloeFlag 
FROM bom_bom a                                        
LEFT JOIN bom_opcomponent b ON b.BomId = a.BomId 
LEFT JOIN bom_parent c ON a.bomid=c.bomid       
LEFT JOIN bas_part d ON b.componentid=d.partid  
LEFT JOIN bas_part  e ON c.parentid=e.partid    
LEFT JOIN inventory f ON d.invcode=f.cinvcode   
LEFT JOIN inventory g ON e.invcode=g.cinvcode   
LEFT JOIN Department dep ON dep.cDepCode=g.cInvDepCode 
LEFT JOIN bom_opcomponentopt opt ON  opt.OptionsId=b.OptionsId 
LEFT JOIN Warehouse w on w.cWhCode=opt.Whcode
LEFT JOIN ComputationUnit c1 ON c1.cComunitCode = f.cProductUnit
LEFT JOIN Inventory_Sub isub ON isub.cInvSubCode=f.cInvCode
WHERE  1=1 AND a.BomType=1 AND  a.BomId={0} 

最后在更新状态

 UPDATE mom_orderdetail SET OrgStatus = Status,Status = 3 ,RelsDate=convert(nvarchar(12),GETDATE(),101),RelsTime = getdate(),RelsUser='{1}',iverifystate=0 WHERE MoDId='{0}'

U8生产订单API接口示例_第4张图片

你可能感兴趣的:(U8,c#,sql,数据库)