repire.sql 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. SELECT
  2. IFNULL(bpa1.cou,0) laidcou,
  3. eq.`specification`,
  4. DATE_FORMAT(mt.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
  5. mt.scores,
  6. mt.`chargeId`,
  7. mt.`checkResult`,
  8. mt.`dealTime`,
  9. eq.`departmentId`,
  10. mt.`details`,
  11. mt.`disposeId`,
  12. mt.`eqClassId`,
  13. mt.`eqCode`,
  14. mt.`eqId`,
  15. mt.`eqName`,
  16. mt.`id`,
  17. mt.`orderStatue`,
  18. DATE_FORMAT(mt.`orderTime`, '%Y-%m-%d %H:%i:%s') orderTime,
  19. mt.`pastureId`,
  20. mt.`phenomenId`,
  21. mt.`pickId`,
  22. mt.`positionId`,
  23. mt.`repairCode`,
  24. mt.`repairDept`,
  25. mt.`repairNote`,
  26. mt.`requesterId`,
  27. DATE_FORMAT(mt.`requestTime`,'%Y-%m-%d %H:%i:%s') requestTime,
  28. DATE_FORMAT(mt.`stopTime`,'%Y-%m-%d %H:%i:%s') stopTime,
  29. p.`name` pastureName,
  30. IF(bpa.cou IS NULL,'未领用','已领用') LYStatue,
  31. IF(rf.cou IS NULL,'未录入','已录入') LRStatue,
  32. mt.flowCompeleted SHStatue,
  33. d.`name` departmentName,
  34. d1.`name` repairDeptName,
  35. e.`empname` requesterName,
  36. e1.`empname` pickName,
  37. em2.`empname` useChargePerson,
  38. em3.`empname` chargePerson,
  39. em4.`empname` shutdownPerson,
  40. mt.shutdownReason,
  41. DATE_FORMAT( mt.shutdownDate,'%Y-%m-%d %H:%i:%s') shutdownDate,
  42. DATE_FORMAT( mt.useChargeDate,'%Y-%m-%d %H:%i:%s') useChargeDate,
  43. mt.workflowNote
  44. FROM
  45. maintain mt
  46. INNER JOIN pasture p
  47. ON p.`id` = mt.`pastureId`
  48. INNER JOIN department d1
  49. ON d1.`id` = mt.`repairDept`
  50. INNER JOIN emp e
  51. ON e.`id` = mt.`requesterId`
  52. LEFT JOIN emp e1
  53. ON e1.`id` = mt.`pickId`
  54. LEFT JOIN emp em2
  55. ON em2.id = mt.useChargeId
  56. LEFT JOIN emp em3
  57. ON em3.id = mt.chargeId
  58. LEFT JOIN emp em4
  59. ON em4.id = mt.shutdownPerson
  60. INNER JOIN equipment eq
  61. ON eq.`id` = mt.`eqId`
  62. LEFT JOIN department d
  63. ON d.`id` = eq.`departmentId`
  64. LEFT JOIN (SELECT RUCode,COUNT(id)cou FROM bigpartapply GROUP BY RUCode ) bpa
  65. ON bpa.`RUCode` = mt.`repairCode`
  66. LEFT JOIN (SELECT repairCode,COUNT(id)cou FROM refuse GROUP BY repairCode)rf
  67. ON rf.`repairCode` = mt.`repairCode`
  68. LEFT JOIN (SELECT RUCode,COUNT(id)cou FROM bigpartapply WHERE statue =0 AND (SHStatus IN (2,3,5,7,9)) GROUP BY RUCode ) bpa1
  69. ON bpa1.`RUCode` = mt.`repairCode`
  70. WHERE
  71. (((mt.requesterId= ? OR mt.pickId =?) OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  72. LEFT JOIN user_role ur
  73. ON ur.`user_id`= u.`id`
  74. LEFT JOIN role r
  75. ON r.`id` = ur.`role_id`
  76. LEFT JOIN role_menu rm
  77. ON r.`id` = rm.`role_id`
  78. LEFT JOIN menu m
  79. ON m.`id` = rm.`menu_id`
  80. WHERE u.`empid` = ? AND m.`path`=? ),0) IN (1,2,3))
  81. AND (eq.departmentId IN (SELECT id FROM department WHERE pastureId =? AND id IN (
  82. SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(ss.www,',',b.seq+1),',',-1) AS 'ids'
  83. FROM
  84. (SELECT @i:=1 i,IFNULL((SELECT GROUP_CONCAT(department_id)SSSS
  85. FROM role_department WHERE role_id = (SELECT MAX(r.id) FROM `user` u
  86. LEFT JOIN user_role ur
  87. ON ur.`user_id`= u.`id`
  88. LEFT JOIN role r
  89. ON r.`id` = ur.`role_id`
  90. LEFT JOIN role_menu rm
  91. ON r.`id` = rm.`role_id`
  92. LEFT JOIN role_department rd
  93. ON r.`id` = rd.`role_id`
  94. LEFT JOIN menu m
  95. ON m.`id` = rm.`menu_id`
  96. WHERE u.`empid` = ? AND m.`path`=?) AND department_id IN (SELECT id FROM department WHERE pastureId = ?)),?) www) ss
  97. JOIN sequence b ON b.seq < (LENGTH(ss.www) - LENGTH(REPLACE(ss.www,',',''))+1)
  98. WHERE ss.i =1
  99. GROUP BY ids
  100. )
  101. )
  102. OR mt.pickId =? OR mt.requesterId= ? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  103. LEFT JOIN user_role ur
  104. ON ur.`user_id`= u.`id`
  105. LEFT JOIN role r
  106. ON r.`id` = ur.`role_id`
  107. LEFT JOIN role_menu rm
  108. ON r.`id` = rm.`role_id`
  109. LEFT JOIN menu m
  110. ON m.`id` = rm.`menu_id`
  111. WHERE u.`empid` =? AND m.`path`=? ),0) IN (2,3))
  112. AND (p.id= ? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  113. LEFT JOIN user_role ur
  114. ON ur.`user_id`= u.`id`
  115. LEFT JOIN role r
  116. ON r.`id` = ur.`role_id`
  117. LEFT JOIN role_menu rm
  118. ON r.`id` = rm.`role_id`
  119. LEFT JOIN menu m
  120. ON m.`id` = rm.`menu_id`
  121. WHERE u.`empid` = ? AND m.`path`=? ),0) = 3)) AND
  122. (p.`name`=? OR ?='现代牧业') AND (mt.repairCode LIKE CONCAT('%',?,'%')OR ?='')
  123. AND (mt.`eqName` LIKE CONCAT('%',?,'%')OR ?='')
  124. AND (mt.`eqCode` LIKE CONCAT('%',?,'%')OR ?='')
  125. AND (mt.`orderStatue` =? OR ?='')
  126. AND (DATE_FORMAT(mt.`requestTime`, '%Y-%m-%d')>=? AND DATE_FORMAT(mt.`requestTime`, '%Y-%m-%d')<=? OR ?='')
  127. AND (
  128. IF (?=0,mt.flowCompeleted IN (2,3) ,
  129. IF(?=1,mt.flowCompeleted=5,mt.flowCompeleted IN (4,6))
  130. )
  131. OR ? = ''
  132. )
  133. ORDER BY mt.`id` DESC