rpt.ashx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <%@ WebHandler Language="C#" Class="rpt" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.SessionState;
  5. using System.Data;
  6. using System.Text;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Linq;
  11. using Curtain.DataAccess;
  12. using DK.XuWei.WebMes;
  13. public class rpt : IHttpHandler, IReadOnlySessionState
  14. {
  15. public void ProcessRequest(HttpContext context)
  16. {
  17. context.Response.ContentType = "text/plain";
  18. using (IDataAccess conn = DataAccess.Create())
  19. {
  20. //主表
  21. if (context.Request["m"].ToString() == "master")
  22. {
  23. //获取查询条件
  24. DateTime dateBegin = Convert.ToDateTime(context.Request["datebeginMaster"]);
  25. DateTime dateEnd = Convert.ToDateTime(context.Request["dateendMaster"]).AddDays(1);
  26. List<CDAParameter> sqlPara = new List<CDAParameter>();
  27. sqlPara.Add(new CDAParameter("accountid", context.Session["accountId"] is object ? Convert.ToInt32(context.Session["accountId"]) : 1));
  28. sqlPara.Add(new CDAParameter("datebegin", dateBegin, DataType.DateTime));
  29. sqlPara.Add(new CDAParameter("dateend", dateEnd, DataType.DateTime));
  30. //主表
  31. if (context.Request["n"].ToString() == "0")
  32. {
  33. //读取报表数据
  34. string sqlStr = @"
  35. SELECT
  36. g.goodscode AS 产品编码,
  37. tt.d_num AS 交坯数,
  38. tt.x_num AS 干补数,
  39. tt.b_num AS 半检不合格数,
  40. tt.f_num AS 复检不合格数,
  41. tt.s_num AS 损坯数,
  42. CASE
  43. WHEN ( tt.b_num + tt.f_num + tt.s_num - tt.x_num ) < 0 THEN
  44. '100%' ELSE to_char(decode(tt.d_num,0,to_number( 0 ),round( ( tt.b_num + tt.f_num + tt.s_num - tt.x_num ) / tt.d_num, 4 ) * 100.00 ),'fm99990.09' ) || '%'
  45. END 报废率,
  46. CASE
  47. WHEN 1- ( tt.b_num + tt.f_num + tt.s_num - tt.x_num ) > 0 THEN
  48. '100%' ELSE to_char(decode(tt.d_num,0,to_number( 0 ),round( 1- ( tt.b_num + tt.f_num + tt.s_num - tt.x_num ) / tt.d_num, 4 ) * 100.00 ),'fm99990.09' ) || '%'
  49. END 合格率
  50. FROM
  51. (
  52. SELECT
  53. t.goodsid,
  54. nvl( sum( decode( t.numtype, 'A', t.id_num, 0 ) ), 0 ) d_num,-- 交坯
  55. nvl( sum( decode( t.numtype, 'B', t.id_num, 0 ) ), 0 ) x_num,-- 干补数
  56. nvl( sum( decode( t.numtype, '2', t.id_num, 0 ) ), 0 ) b_num,-- 半检不合格数
  57. nvl( sum( decode( t.numtype, '3', t.id_num, 0 ) ), 0 ) f_num,-- 复检不合格数
  58. nvl( sum( decode( t.numtype, '0', t.id_num, 0 ) ), 0 ) s_num -- 损坯数
  59. FROM
  60. (
  61. SELECT
  62. gdd.goodsid,
  63. 'A' numtype,
  64. count( gdd.groutingdailydetailid ) id_num
  65. FROM
  66. tp_pm_groutingdailydetail gdd
  67. LEFT JOIN TP_PC_GROUTINGLINE gl on gl.GROUTINGLINEID=gdd.GROUTINGLINEID
  68. WHERE
  69. gdd.groutingflag = '1'
  70. AND gdd.valueflag = '1'
  71. AND gdd.accountid = 1
  72. AND gdd.deliverflag = '1'
  73. AND gdd.delivertime >= @datebegin@
  74. AND gdd.delivertime < @dateend@
  75. AND (@BUILDINGNO@ IS NULL OR instr(gl.BUILDINGNO , @BUILDINGNO@) > 0)
  76. AND (@HIGHPRESSUREFLAG@ IS NULL OR instr(gl.HIGHPRESSUREFLAG , @HIGHPRESSUREFLAG@) > 0)
  77. GROUP BY
  78. gdd.goodsid
  79. UNION ALL-- 干补数
  80. SELECT
  81. p.goodsid,
  82. 'B' numtype,
  83. count( p.productiondataid ) id_num
  84. FROM
  85. TP_PM_PRODUCTIONDATA p
  86. LEFT JOIN TP_PC_GROUTINGLINE gl on gl.GROUTINGLINEID=p.GROUTINGLINEID
  87. WHERE
  88. p.VALUEFLAG = 1
  89. AND p.accountid = 1
  90. AND p.PROCEDUREID = 18
  91. AND p.createtime >= @datebegin@
  92. AND p.createtime < @dateend@
  93. AND (@BUILDINGNO@ IS NULL OR instr(gl.BUILDINGNO , @BUILDINGNO@) > 0)
  94. AND (@HIGHPRESSUREFLAG@ IS NULL OR instr(gl.HIGHPRESSUREFLAG , @HIGHPRESSUREFLAG@) > 0)
  95. GROUP BY
  96. p.goodsid
  97. UNION ALL-- 半检不合格数 复检不合格数 损坯数
  98. SELECT
  99. sp.goodsid,
  100. sp.SCRAPTYPE numtype,
  101. count( sp.scrapproductid ) id_num
  102. FROM
  103. tp_pm_scrapproduct sp
  104. LEFT JOIN TP_PC_GROUTINGLINE gl on gl.GROUTINGLINEID=sp.GROUTINGLINEID
  105. WHERE
  106. sp.valueflag = '1'
  107. AND sp.accountid = 1
  108. AND sp.auditstatus = 1
  109. AND sp.KILNID IS NULL
  110. AND sp.SCRAPTYPE <> '1'
  111. AND sp.AUDITDATE >= @datebegin@
  112. AND sp.AUDITDATE < @dateend@
  113. AND (@BUILDINGNO@ IS NULL OR instr(gl.BUILDINGNO , @BUILDINGNO@) > 0)
  114. AND (@HIGHPRESSUREFLAG@ IS NULL OR instr(gl.HIGHPRESSUREFLAG , @HIGHPRESSUREFLAG@) > 0)
  115. GROUP BY
  116. sp.goodsid,
  117. sp.SCRAPTYPE
  118. ) t
  119. GROUP BY
  120. t.goodsid
  121. ) tt
  122. INNER JOIN tp_mst_goods g ON tt.goodsid = g.goodsid
  123. LEFT JOIN TP_MST_GOODSTYPE GT ON g.GOODSTYPEID=GT.GOODSTYPEID
  124. WHERE (@goodstypecode@ IS NULL OR instr(gt.goodstypecode,@goodstypecode@) = 1) ";
  125. if (!string.IsNullOrWhiteSpace(context.Request["goodscode"] + ""))
  126. {
  127. sqlStr += " AND instr(g.goodscode, @goodscode@) > 0 \n";
  128. sqlPara.Add(new CDAParameter("goodscode", context.Request["goodscode"]));
  129. }
  130. sqlStr += " order by g.goodscode";
  131. sqlPara.Add(new CDAParameter("BUILDINGNO", context.Request["workshopcodeMaster"].ToString()));
  132. sqlPara.Add(new CDAParameter("HIGHPRESSUREFLAG",context.Request["HIGHPRESSUREFLAG"]));
  133. sqlPara.Add(new CDAParameter("goodstypecode", context.Request["goodstypecode"].ToString()));
  134. //直接获取不分页数据
  135. JsonResult jsonresult = Easyui.ExecuteJsonResult(conn, sqlStr, sqlPara);
  136. context.Response.Write(jsonresult.ToJson());
  137. }
  138. //子表
  139. if (context.Request["n"].ToString() == "1")
  140. {
  141. string sqlStr = "select g.goodscode 产品编码\n" +
  142. " ,ppp.b_out_num 本烧出窑数\n" +
  143. " ,(ppp.b_out_num - ppp.b_bad_num) 本烧合格数\n" +
  144. " ,(ppp.c_out_num - ppp.c_bad_num) 重烧合格数\n" +
  145. " ,decode(ppp.b_out_num,0,to_number( 0 ),round( ( ppp.b_out_num - ppp.b_bad_num + ppp.c_out_num - ppp.c_bad_num ) / ppp.b_out_num, 4 ) ) *100 ||'%' 综合合格率\n" +
  146. "from (\n" +
  147. " SELECT pp.goodsid ,\n" +
  148. " nvl(sum(decode(pp.OUTflag, 1, b_out_num, 0)), 0) b_out_num,\n" +
  149. " nvl(sum(decode(pp.OUTflag, 0, b_bad_num, 0)), 0) b_bad_num,\n" +
  150. " nvl(sum(decode(pp.OUTflag, 1, c_out_num, 0)), 0) c_out_num,\n" +
  151. " nvl(sum(decode(pp.OUTflag, 0, c_bad_num, 0)), 0) c_bad_num\n" +
  152. " FROM (\n" +
  153. " select p.goodsid\n" +
  154. " ,1 AS OUTflag\n" +
  155. " ,nvl(sum(case when ((p.procedureid = 11 AND p.valueflag = '1') OR (p.procedureid =104 AND p.isrefire = '0' AND p.checkflag = '1')) then 1 else 0 end), 0) b_out_num -- 本烧出窑数\n" +
  156. " ,0 b_bad_num -- 本烧不合格数\n" +
  157. " ,nvl(sum(case when ((p.procedureid = 58 AND p.valueflag = '1') OR (p.procedureid =104 AND p.isrefire = '6' AND p.checkflag = '1')) then 1 else 0 end), 0) c_out_num -- 重烧出窑数\n" +
  158. " ,0 c_bad_num -- 重烧不合格数\n" +
  159. " from tp_pm_productiondata p\n" +
  160. " INNER JOIN tp_mst_goods g ON p.goodsid = g.goodsid\n" +
  161. " LEFT JOIN TP_MST_GOODSTYPE GT ON g.GOODSTYPEID=GT.GOODSTYPEID\n" +
  162. " LEFT JOIN TP_PC_GROUTINGLINE gl on gl.GROUTINGLINEID=p.GROUTINGLINEID\n" +
  163. " where p.accountid = @accountid@\n" +
  164. " and p.procedureid in (11, 58, 104)\n" +
  165. " and p.createtime >= @datebegin@\n" +
  166. " and p.createtime < @dateend@\n" +
  167. " AND (@BUILDINGNO@ IS NULL OR instr(gl.BUILDINGNO , @BUILDINGNO@) > 0) " +
  168. " AND (@HIGHPRESSUREFLAG@ IS NULL OR instr(gl.HIGHPRESSUREFLAG , @HIGHPRESSUREFLAG@) > 0)" +
  169. " AND (@goodstypecode@ IS NULL OR instr(gt.goodstypecode,@goodstypecode@) = 1)";
  170. // 产品编码条件修正 fenglinyong modify 2022-05-10
  171. if (!string.IsNullOrWhiteSpace(context.Request["goodscode"] + ""))
  172. {
  173. sqlStr += " and instr(p.goodscode,@GOODSCODE@) > 0 \n";
  174. sqlPara.Add(new CDAParameter("GOODSCODE", context.Request["goodscode"]));
  175. }
  176. sqlStr += @" GROUP BY p.goodsid
  177. UNION ALL
  178. select p.goodsid
  179. ,0 AS OUTflag
  180. ,0 b_out_num
  181. ,nvl(sum(case when p.goodsleveltypeid in(6,7) and p.isrefire='0' then 1 else 0 end), 0) b_bad_num -- 本烧不合格数
  182. ,0 c_out_num
  183. ,nvl(sum(case when p.goodsleveltypeid in(6,7)and p.isrefire='6' then 1 else 0 end), 0) c_bad_num -- 重烧不合格数
  184. from (
  185. select distinct p.goodsleveltypeid
  186. ,p.barcode
  187. ,p.goodsid
  188. ,p.ISREFIRE
  189. from tp_pm_productiondata p
  190. inner join tp_pm_groutingdailydetail gdd on gdd.groutingdailydetailid = p.groutingdailydetailid
  191. LEFT JOIN TP_PC_GROUTINGLINE gl on gl.GROUTINGLINEID=p.GROUTINGLINEID
  192. INNER JOIN TP_PM_DEFECT dfc on dfc.productiondataid=p.productiondataid
  193. INNER JOIN tp_mst_goods g ON p.goodsid = g.goodsid
  194. LEFT JOIN TP_MST_GOODSTYPE GT ON g.GOODSTYPEID=GT.GOODSTYPEID
  195. where p.accountid = @accountid@
  196. AND P.VALUEFLAG = 1
  197. and p.modeltype IN (-1, -4, -5)
  198. and p.CHECKBATCHNO = 1
  199. and length(p.kilncarbatchno) > 0
  200. and p.createtime >= @datebegin@
  201. and p.createtime < @dateend@
  202. AND (@BUILDINGNO@ IS NULL OR instr(gl.BUILDINGNO , @BUILDINGNO@) > 0)
  203. AND (@HIGHPRESSUREFLAG@ IS NULL OR instr(gl.HIGHPRESSUREFLAG , @HIGHPRESSUREFLAG@) > 0)
  204. AND (@goodstypecode@ IS NULL OR instr(gt.goodstypecode,@goodstypecode@) = 1) ";
  205. // 产品编码条件修正 fenglinyong modify 2022-05-10
  206. if (!string.IsNullOrWhiteSpace(context.Request["goodscode"] + ""))
  207. {
  208. sqlStr += " and instr(p.goodscode,@GOODSCODE@) > 0 \n";
  209. sqlPara.Add(new CDAParameter("GOODSCODE", context.Request["goodscode"]));
  210. }
  211. sqlStr += " )P GROUP BY p.goodsid ) pp group by pp.goodsid) ppp\n" +
  212. " inner join tp_mst_goods g\n" +
  213. " on g.goodsid = ppp.goodsid\n" +
  214. " order by g.goodscode";
  215. sqlPara.Add(new CDAParameter("BUILDINGNO", context.Request["workshopcodeMaster"].ToString()));
  216. sqlPara.Add(new CDAParameter("HIGHPRESSUREFLAG",context.Request["HIGHPRESSUREFLAG"]));
  217. sqlPara.Add(new CDAParameter("goodstypecode", context.Request["goodstypecode"].ToString()));
  218. //直接获取不分页数据
  219. JsonResult jsonresult = Easyui.ExecuteJsonResult(conn, sqlStr, sqlPara);
  220. context.Response.Write(jsonresult.ToJson());
  221. }
  222. }
  223. }
  224. }
  225. public bool IsReusable
  226. {
  227. get
  228. {
  229. return false;
  230. }
  231. }
  232. }