ClssSql.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. class ClassSqls:
  2. # 共用的
  3. # 存储过程
  4. ccc = """alter FUNCTION [dbo].[f_splitSTR](
  5. @s varchar(8000), --待分拆的字符串
  6. @split varchar(10) --数据分隔符
  7. )RETURNS @re TABLE(col varchar(100))
  8. AS
  9. BEGIN
  10. DECLARE @splitlen int
  11. SET @splitlen = LEN(@split + 'a') - 2
  12. WHILE CHARINDEX(@split,@s) > 0
  13. BEGIN
  14. INSERT @re VALUES(LEFT(@s,CHARINDEX(@split,@s) - 1))
  15. SET @s = STUFF(@s,1,CHARINDEX(@split,@s)+@splitlen,'')
  16. END
  17. INSERT @re VALUES(@s)
  18. UPDATE A SET a.col=b.NAME FROM @re A,SALM B WITH (NOLOCK) WHERE A.COL=B.SAL_NO
  19. RETURN
  20. END"""
  21. aaaa="""select left(Convert(varchar(100), no_dd, 23), 11) as no_dd,create_time,update_time,bg_no,bg_id,zc_no,(
  22. select
  23. (
  24. stuff(
  25. (select ',' + col from f_splitSTR(rtrim((replace(replace(replace(replace(sal_no,'[',''),']',''),'''',''),' ',''))),',') for xml path('')),1,1,''))
  26. ) as sal_no,create_user,update_user,mo_no from django_mf_bg"""
  27. # 1、这里是插入通知单自定义表的单号
  28. CommonSql_z = """INSERT INTO MF_TZ_Z(TZ_NO) SELECT A.TZ_NO FROM MF_TZ A WITH (NOLOCK) LEFT JOIN MF_TZ_Z B WITH(NOLOCK) ON A.TZ_NO=B.TZ_NO WHERE ISNULL(B.TZ_NO,'')='' """
  29. # 2、生产单号sql
  30. CommonSqlNo = """select max(right(bg_no,11)) as bg_no from django_mf_bg where left(Convert(varchar(100), no_dd, 23), 11) = CONVERT(varchar(10),GETDATE(),120) and bg_id='{0}'"""
  31. # 3、查询(Django_tf_bg)表身需要删除的单据
  32. CommonTfSql = """select zt_no,bg_id,qty,zl from Django_tf_bg where bg_no_id='{0}'"""
  33. # 4、单据查询
  34. # 查询表头
  35. CommonMf_sql = """select left(Convert(varchar(100), no_dd, 23), 11) as no_dd,create_time,update_time,bg_no,bg_id,zc_no,sal_no,create_user,update_user,mo_no from django_mf_bg where bg_no='{0}'"""
  36. CommonTf_sql = """select left(Convert(varchar(100), no_dd, 23), 11) as no_dd,itm,bg_id,mo_no,zt_no,prd_no,prd_name,cc,zy,qty,zl,ms,rem,dd,prd_rem,bg_no_id,sal_no,zc_no_up,zc_no_end as zc_no_dn
  37. from django_tf_bg where bg_no_id='{0}' order by itm asc"""
  38. # 5、查看用户信息
  39. CommonUsers = """select a.username as value,cast(a.username as varchar(20))+'--'+b.name as label from users a left join SunSystem..PSWD b on a.username=b.usr and b.compno='01'"""
  40. # 5、弹窗条件查询的sql
  41. # 查询通知单
  42. CommonFilter = """select left(Convert(varchar(100), no_dd, 23), 11) as no_dd,create_time,update_time,bg_no,bg_id,zc_no,(
  43. select
  44. (
  45. stuff(
  46. (select ',' + col from f_splitSTR(rtrim((replace(replace(replace(replace(sal_no,'[',''),']',''),'''',''),' ',''))),',') for xml path('')),1,1,''))
  47. ) as sal_no,create_user,update_user,mo_no from django_mf_bg {0}"""
  48. # 各类单据过滤查询
  49. TzInfoJs = """select 0 as zl, a.zc_no,a.mo_no,a.tz_no as zt_no,a.mrp_no as prd_no,c.name as prd_name,isnull(a.Qty,0)-isnull(e.qty_js_lx,0)as qty,
  50. isnull(a.Qty,0)-isnull(e.qty_js_lx,0) as yscl,b.sc_lx as cc,b.zy_lx as zy,a.rem as ms,a.rrem as rem,d.dd,c.rem as prd_rem,isnull(a.qty,0) as totalqty,
  51. zc_no_up = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_up),
  52. zc_no_dn = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_dn)
  53. from MF_TZ a
  54. left join (select aa.sc_lx,aa.zy_lx,aa.os_no,bb.mo_no from
  55. tf_pos_z aa,mf_mo bb,tf_pos cc where cc.os_id='SO' AND AA.OS_ID=CC.OS_ID and aa.itm=cc.itm and aa.os_no=cc.os_no and cc.est_itm=bb.est_itm and aa.os_no=bb.so_no)b on a.mo_no=b.mo_no
  56. left join prdt c on a.mrp_no=c.prd_no
  57. left join prdt_z d on c.prd_no=d.prd_no
  58. left join mF_TZ_z e on a.tz_no=e.tz_no
  59. where isnull(a.close_id,'')<>'T' and isnull(a.Qty,0)>isnull(e.qty_js_lx,0) and a.zc_no='B02' and a.mo_no in('MO06180004','MO06220004')"""
  60. TzInfoPg = """select 0 as zl, a.zc_no,a.mo_no,a.tz_no as zt_no,a.mrp_no as prd_no,c.name as prd_name,isnull(e.qty_js_lx,0)-isnull(e.qty_pg_lx,0)
  61. as qty,isnull(e.qty_js_lx,0)-isnull(e.qty_pg_lx,0) as yscl,b.sc_lx as cc,b.zy_lx as zy,a.rem as ms,a.rrem as rem,d.dd,c.rem as prd_rem,isnull(e.qty_js_lx,0)as totalqty,
  62. zc_no_up = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_up),
  63. zc_no_dn = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_dn)
  64. from MF_TZ a
  65. left join (select aa.sc_lx,aa.zy_lx,aa.os_no,bb.mo_no from
  66. tf_pos_z aa,mf_mo bb,tf_pos cc where cc.os_id='SO' AND AA.OS_ID=CC.OS_ID and aa.itm=cc.itm and aa.os_no=cc.os_no and cc.est_itm=bb.est_itm and aa.os_no=bb.so_no)b on a.mo_no=b.mo_no
  67. left join prdt c on a.mrp_no=c.prd_no
  68. left join prdt_z d on c.prd_no=d.prd_no
  69. left join mF_TZ_z e on a.tz_no=e.tz_no
  70. where isnull(a.close_id,'')<>'T' and isnull(e.qty_js_lx,0)>isnull(e.qty_pg_lx,0) and a.zc_no='{0}' and a.mo_no='{1}'"""
  71. TzInfoSh = """select 0 as zl, a.zc_no,a.mo_no,a.tz_no as zt_no,a.mrp_no as prd_no,c.name as prd_name,isnull(e.qty_pg_lx,0)-isnull(e.qty_sh_lx,0)
  72. as qty,isnull(e.qty_pg_lx,0)-isnull(e.qty_sh_lx,0) as yscl,b.sc_lx as cc,b.zy_lx as zy,a.rem as ms,a.rrem as rem,d.dd,c.rem as prd_rem,isnull(e.qty_pg_lx,0) as totalqty,
  73. zc_no_up = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_up),
  74. zc_no_dn = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_dn) ,
  75. sal_no=(select top 1 c1.sal_no+'-'+c1.name as sal_no from django_mf_bg a1,django_tf_bg b1,salm c1 where
  76. REPLACE(REPLACE(a1.sal_no,''']',''),'[''','')=c1.sal_no and a1.bg_no=b1.bg_no_id and a1.bg_id='PG' and b1.zt_no=a.tz_no)
  77. from MF_TZ a
  78. left join (select aa.sc_lx,aa.zy_lx,aa.os_no,bb.mo_no from
  79. tf_pos_z aa,mf_mo bb,tf_pos cc where cc.os_id='SO' AND AA.OS_ID=CC.OS_ID and aa.itm=cc.itm and aa.os_no=cc.os_no and cc.est_itm=bb.est_itm and aa.os_no=bb.so_no)b on a.mo_no=b.mo_no
  80. left join prdt c on a.mrp_no=c.prd_no
  81. left join prdt_z d on c.prd_no=d.prd_no
  82. left join mF_TZ_z e on a.tz_no=e.tz_no
  83. where isnull(a.close_id,'')<>'T' and isnull(e.qty_pg_lx,0)>isnull(e.qty_sh_lx,0) and a.zc_no='{0}' and a.mo_no='{1}'"""
  84. TzInfoZy = """select 0 as zl, a.zc_no,a.mo_no,a.tz_no as zt_no,a.mrp_no as prd_no,c.name as prd_name,isnull(e.qty_sh_lx,0)-isnull(e.qty_zy_lx,0)
  85. as qty,isnull(e.qty_sh_lx,0)-isnull(e.qty_zy_lx,0) as yscl, b.sc_lx as cc,b.zy_lx as zy,a.rem as ms,a.rrem as rem,d.dd,c.rem as prd_rem,isnull(e.qty_sh_lx,0) as totalqty,
  86. zc_no_up = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_up),
  87. zc_no_dn = (select isnull(zc_no+'-'+name,'') from zc_no where zc_no=a.zc_no_dn)
  88. from MF_TZ a
  89. left join (select aa.sc_lx,aa.zy_lx,aa.os_no,bb.mo_no from
  90. tf_pos_z aa,mf_mo bb,tf_pos cc where cc.os_id='SO' AND AA.OS_ID=CC.OS_ID and aa.itm=cc.itm and aa.os_no=cc.os_no and cc.est_itm=bb.est_itm and aa.os_no=bb.so_no)b on a.mo_no=b.mo_no
  91. left join prdt c on a.mrp_no=c.prd_no
  92. left join prdt_z d on c.prd_no=d.prd_no
  93. left join mF_TZ_z e on a.tz_no=e.tz_no
  94. where isnull(a.close_id,'')<>'T' and isnull(e.qty_sh_lx,0)>isnull(e.qty_zy_lx,0) and a.zc_no='{0}' and a.mo_no='{1}' and a.ZC_NO_DN='{2}'"""
  95. # 批量导入用户
  96. InsetUser = """insert into users(last_login,is_superuser,username,first_name,last_name,email,is_staff,is_active,date_joined,password)
  97. select '' as last_login,0 as is_superuser, usr as username,'' as first_name,'' as last_name,'123456@qq.com' as email,
  98. 1 as is_staff,1 as is_active,'' as date_joined,'pbkdf2_sha256$150000$cr8SzfavxM7f$2hVNA/mT/iVW4aC/ibGUjjMPcoqGl0JdCJnYqoqmt68=' as password
  99. from SunSystem..PSWD where usr not in(select username from users)and compno='01'"""
  100. # 接收单
  101. # 更新通知单栏位
  102. BgUpSql = """update a set a.qty_js_lx=b.qty,a.qty1_js_lx=b.zl from MF_TZ_Z a,(select sum(isnull(qty,0)) as qty,sum(isnull(cast(zl as float),0)) as zl,
  103. zt_no from Django_tf_bg where zt_no='{0}' and bg_id='{1}' group by zt_no)b WHERE a.tz_no=b.zt_no"""
  104. # 删除的时候更新
  105. BgUpdel = """update MF_TZ_Z set qty_js_lx=isnull(qty_js_lx,0)-{0},qty1_js_lx=isnull(qty1_js_lx,0)-{1} where tz_no='{2}'"""
  106. # 查询单据的时候计算应生产量
  107. BgYscl = """SELECT ISNULL(A.QTY,0)-ISNULL(B.QTY_JS_LX,0) AS qty,a.tz_no,a.QTY as totalqty FROM MF_TZ A,MF_TZ_Z B WHERE A.TZ_NO=B.TZ_NO AND A.TZ_NO='{0}'"""
  108. # 派工单
  109. # 删除的时候更新
  110. PgUpdel = """update MF_TZ_Z set qty_pg_lx=isnull(qty_pg_lx,0)-{0},qty1_pg_lx=isnull(qty1_pg_lx,0)-{1} where tz_no='{2}'"""
  111. PgUpSql = """update a set a.qty_pg_lx=b.qty,a.qty1_pg_lx=b.zl from MF_TZ_Z a,(select sum(isnull(qty,0)) as qty,sum(isnull(cast(zl as float),0)) as zl,
  112. zt_no from Django_tf_bg where zt_no='{0}' and bg_id='{1}' group by zt_no)b WHERE a.tz_no=b.zt_no"""
  113. PgYscl = """select isnull(qty_js_lx,0)-isnull(qty_pg_lx,0) as qty,tz_no,qty_js_lx as totalqty from MF_TZ_Z where tz_no='{0}'"""
  114. # 收货单
  115. # 删除的时候更新
  116. ShUpdel = """update MF_TZ_Z set qty_sh_lx=isnull(qty_sh_lx,0)-{0},qty1_sh_lx=isnull(qty1_sh_lx,0)-{1} where tz_no='{2}'"""
  117. ShUpSql = """update a set a.qty_sh_lx=b.qty,a.qty1_sh_lx=b.zl from MF_TZ_Z a,(select sum(isnull(qty,0)) as qty,sum(isnull(cast(zl as float),0)) as zl,
  118. zt_no from Django_tf_bg where zt_no='{0}' and bg_id='{1}' group by zt_no)b WHERE a.tz_no=b.zt_no"""
  119. ShYscl = """select isnull(qty_pg_lx,0)-isnull(qty_sh_lx,0) as qty,tz_no,qty_pg_lx as totalqty from MF_TZ_Z where tz_no='{0}'"""
  120. # 转移单
  121. # 删除的时候更新
  122. ZyUpdel = """update MF_TZ_Z set qty_zy_lx=isnull(qty_zy_lx,0)-{0},qty1_zy_lx=isnull(qty1_zy_lx,0)-{1} where tz_no='{2}'"""
  123. ZyUpSql = """update a set a.qty_zy_lx=b.qty,a.qty1_zy_lx=b.zl from MF_TZ_Z a,(select sum(isnull(qty,0)) as qty,sum(isnull(cast(zl as float),0)) as zl,
  124. zt_no from Django_tf_bg where zt_no='{0}' and bg_id='{1}' group by zt_no)b WHERE a.tz_no=b.zt_no"""
  125. ZyYscl = """select isnull(qty_sh_lx,0)-isnull(qty_zy_lx,0) as qty,tz_no,qty_sh_lx as totalqty from MF_TZ_Z where tz_no='{0}'"""
  126. # 通知单以生产量、自定义栏位
  127. ZySelfz = """select isnull(a.qty_fin,0) as qty_fin,isnull(a.qty,0) as qty from MF_TZ a,MF_TZ_z b where a.tz_no=b.tz_no and a.tz_no='{0}'"""
  128. ZyUpFin = """update a set a.QTY_FIN=b.qty_zy_lx from MF_TZ a,MF_TZ_z b where a.tz_no=b.tz_no and a.tz_no='{0}'"""
  129. ZyUpClose = """update mf_tz set close_id='T' where tz_no='{0}'"""
  130. ZyUpNoClose = """update mf_tz set close_id='F' where tz_no='{0}'"""