OutPutDataDal.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Cksoft.Data;
  2. using DllEapEntity.Dtos;
  3. using DllEapEntity.OFILM;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Text;
  7. namespace DllEapDal.OFILM
  8. {
  9. public class OutPutDataDal
  10. {
  11. private IDatabase db;
  12. public OutPutDataDal(IDatabase db)
  13. {
  14. this.db = db;
  15. }
  16. public LayuiModel<OutPutData> Get(string fcode, DateTime start, DateTime end, string recipe, int pageIndex, int pageSize)
  17. {
  18. string sql= $@"SELECT b.FName Factory,a.Plant Plant,a.Floor Floor,a.FCode FCode,a.ProcessCode ProcessCode,a.Recipe Recipe,a.FCount FCount,a.SDate SDate,a.EDate EDate FROM `v_maccountdetail` a LEFT JOIN factoryregion b on a.FactoryId=b.iD where 1=1 ";
  19. string ss = $@" and a.SDate>='{start.ToString("yyyy-MM-dd HH:mm:dd")}' and a.SDate<= '{end.ToString("yyyy-MM-dd HH:mm:dd")}' ";
  20. if (!string.IsNullOrEmpty(fcode))
  21. {
  22. ss += $@" and a.fcode like '%{fcode}%' ";
  23. }
  24. if (!string.IsNullOrEmpty(recipe))
  25. {
  26. ss += $@" and a.Recipe like '%{recipe}%' ";
  27. }
  28. string str = $@" limit {(pageIndex - 1) * pageSize},{pageSize}";
  29. return new LayuiModel<OutPutData>()
  30. {
  31. code = 1,
  32. count = Convert.ToInt32(db.FindObject("select count(1) from v_maccountdetail a where 1=1 " + ss)),
  33. data = db.FindList<OutPutData>(sql + ss + str)
  34. };
  35. }
  36. public LayuiModel<OutPutData> GetCount(string fcode, DateTime start, DateTime end, string recipe, int pageIndex, int pageSize)
  37. {
  38. string str = $@"select `a`.`SDate` AS `SDate`,`a`.`EDate` AS `EDate`,`b`.`FCode` AS `FCode`,`c`.`FCount` AS `FCount`,substring_index(replace(replace(replace(`a`.`PName`,' ','-'),'_','-'),'.','-'),'-',1) AS `Recipe`,`h`.`FName` AS `Factory`,`d`.`PCode` AS `ProcessCode`,`f`.`FName` AS `Floor`,`g`.`FName` AS `Plant` from ((((((`maccountmst` `a` join `machine` `b` on((`a`.`MacID` = `b`.`ID`))) join `maccountdetail` `c` on((`c`.`MstID` = `a`.`ID`))) join `mactprocess` `d` on((`a`.`MacID` = `d`.`MacID`))) join `factoryregion` `e` on((`b`.`RegionId` = `e`.`Id`))) join `factoryregion` `f` on((`e`.`ParentId` = `f`.`Id`))) join `factoryregion` `g` on((`f`.`ParentId` = `g`.`Id`)) join `factoryregion` h on ((`b`.`FactoryId` = `h`.`Id`))) where ((`c`.`TypeID` = 0) and (`g`.`Id` <> 207) and (`f`.`Id` <> 281) and (`f`.`Id` <> 213) and (`f`.`Id` <> 210) and (`f`.`Id` <> 45) and (`f`.`Id` <> 13)) ";
  39. string sql = $@"select * from ({str}) t where 1=1 ";
  40. string ss = $@" and t.SDate>='{start.ToString("yyyy-MM-dd HH:mm:dd")}' and t.SDate<= '{end.ToString("yyyy-MM-dd HH:mm:dd")}' ";
  41. if (!string.IsNullOrEmpty(fcode))
  42. {
  43. ss += $@" and t.fcode like '%{fcode}%' ";
  44. }
  45. if (!string.IsNullOrEmpty(recipe))
  46. {
  47. ss += $@" and t.Recipe like '%{recipe}%' ";
  48. }
  49. string strt = $@" limit {(pageIndex - 1) * pageSize},{pageSize}";
  50. var count = Convert.ToInt32(db.FindObject($@"select count(1) from ({str}) t where 1=1 " + ss));
  51. var data = db.FindList<OutPutData>(sql + ss + strt);
  52. return new LayuiModel<OutPutData>()
  53. {
  54. code = 1,
  55. count=count,
  56. data=data
  57. };
  58. }
  59. }
  60. }