getBigupkeepList.sql 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. SELECT
  2. qq.*
  3. FROM
  4. (SELECT
  5. IFNULL(bpa1.cou,0) laidcou,
  6. buk.id,
  7. buk.`eqId`,
  8. buk.bigupkeeptemplateId,
  9. CONCAT(
  10. '名称:',
  11. but.`upkeepName`,
  12. '|保养级别:',
  13. but.`upkeepLevel`
  14. ) upNameLevel,
  15. buk.`upkeepCode`,
  16. buk.scores,
  17. buk.workflowNote,
  18. DATE_FORMAT(buk.chargeDate,'%Y-%m-%d %H:%i:%s') chargeDate,
  19. DATE_FORMAT(buk.useChargeDate,'%Y-%m-%d %H:%i:%s') useChargeDate,
  20. DATE_FORMAT(buk.finishedTime,'%Y-%m-%d %H:%i:%s') finishedTime,
  21. em1.`empname` upkeepPerson,
  22. em2.`empname` useChargePerson,
  23. em3.`empname` chargePerson,
  24. em4.empname deptChargePerson,IFNULL( buk.useEmpId, e.employeeId) useEmpId,IFNULL(em5.empname ,em.empname) useEmpName,
  25. DATE_FORMAT(buk.deptChargeDate,'%Y-%m-%d %H:%i:%s') deptChargeDate,
  26. buk.deptChargeId,
  27. IFNULL(em.`empname`,employeName) employeName,
  28. e.employeeId,
  29. e.`departmentId`,
  30. buk.upkeepPerson upkeepPersonId,
  31. e.`eqCode`,
  32. e.`eqName`,
  33. e.`specification`,
  34. p.`name` pastureName,
  35. d.`name` departmentName,
  36. IF(
  37. buk.`statue` = 0
  38. AND (DATE_FORMAT(NOW(), '%Y-%m-%d') = buk.`plantime` OR buk.`flowCompeleted`>1
  39. OR DATE_FORMAT(DATE_ADD(NOW(),INTERVAL -1 DAY), '%Y-%m-%d') = buk.`plantime` ),
  40. 1,
  41. buk.`statue`
  42. ) statue,
  43. IF(bpa.cou IS NULL,'未领用','已领用') LYStatue,
  44. IF(rf.cou IS NULL,'未录入','已录入') LRStatue,
  45. buk.flowCompeleted SHStatue,
  46. case
  47. when (select id from video where upkeepId =buk.id) is null then '未录制'
  48. when (select id from video where upkeepId =buk.id and endRecord =2 ) is not null then '录制中'
  49. when (select id from video where upkeepId =buk.id and newCreateTime=createTime and location <>'') is not null then '已录制'
  50. else '已录制上传中'
  51. end as videoTxt,# 录制状态
  52. ifnull((select location from video where upkeepId =buk.id),'') videoPath, # 录制地址
  53. buk.`plantime`
  54. FROM
  55. bigupkeep buk
  56. INNER JOIN equipment e
  57. ON buk.`eqId` = e.`id`
  58. INNER JOIN pasture p
  59. ON p.`id` = e.`pastureId`
  60. LEFT JOIN department d
  61. ON e.`departmentId` = d.`id`
  62. LEFT JOIN emp em
  63. ON em.id = e.employeeId
  64. LEFT JOIN emp em1
  65. ON em1.id = buk.upkeepPerson
  66. LEFT JOIN emp em2
  67. ON em2.id = buk.useChargeId
  68. LEFT JOIN emp em3
  69. ON em3.id = buk.chargeId
  70. LEFT JOIN emp em4
  71. ON em4.id = buk.deptChargeId
  72. LEFT JOIN emp em5
  73. ON em5.id = buk.useEmpId
  74. LEFT JOIN bigupkeeptemplate but
  75. ON but.id = buk.bigupkeeptemplateId
  76. LEFT JOIN (SELECT RUCode,COUNT(id)cou FROM bigpartapply GROUP BY RUCode ) bpa
  77. ON bpa.`RUCode` = buk.`upkeepCode`
  78. LEFT JOIN (SELECT repairCode,COUNT(id)cou FROM refuse GROUP BY repairCode)rf
  79. ON rf.`repairCode` = buk.`upkeepCode`
  80. LEFT JOIN (SELECT RUCode,COUNT(id)cou FROM bigpartapply WHERE statue =0 AND (SHStatus IN (2,3,5,7,9)) GROUP BY RUCode ) bpa1
  81. ON bpa1.`RUCode` = buk.`upkeepCode`
  82. WHERE
  83. ((buk.upkeepPerson= ? OR buk.useEmpId=? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  84. LEFT JOIN user_role ur
  85. ON ur.`user_id`= u.`id`
  86. LEFT JOIN role r
  87. ON r.`id` = ur.`role_id`
  88. LEFT JOIN role_menu rm
  89. ON r.`id` = rm.`role_id`
  90. LEFT JOIN menu m
  91. ON m.`id` = rm.`menu_id`
  92. WHERE u.`empid` = ? AND m.`path`=?),0) IN (1,2,3))
  93. AND (e.departmentId IN (SELECT id FROM department WHERE pastureId =? AND id IN (
  94. SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(ss.www,',',b.seq+1),',',-1) AS 'ids'
  95. FROM
  96. (SELECT @i:=1 i,IFNULL((SELECT GROUP_CONCAT(department_id)SSSS
  97. FROM role_department WHERE role_id = (SELECT MAX(r.id) FROM `user` u
  98. LEFT JOIN user_role ur
  99. ON ur.`user_id`= u.`id`
  100. LEFT JOIN role r
  101. ON r.`id` = ur.`role_id`
  102. LEFT JOIN role_menu rm
  103. ON r.`id` = rm.`role_id`
  104. LEFT JOIN role_department rd
  105. ON r.`id` = rd.`role_id`
  106. LEFT JOIN menu m
  107. ON m.`id` = rm.`menu_id`
  108. WHERE u.`empid` = ? AND m.`path`=?) AND department_id IN (SELECT id FROM department WHERE pastureId = ?)),?) www) ss
  109. JOIN sequence b ON b.seq < (LENGTH(ss.www) - LENGTH(REPLACE(ss.www,',',''))+1)
  110. WHERE ss.i =1
  111. GROUP BY ids
  112. )
  113. )
  114. OR buk.upkeepPerson= ? OR buk.useEmpId=? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  115. LEFT JOIN user_role ur
  116. ON ur.`user_id`= u.`id`
  117. LEFT JOIN role r
  118. ON r.`id` = ur.`role_id`
  119. LEFT JOIN role_menu rm
  120. ON r.`id` = rm.`role_id`
  121. LEFT JOIN menu m
  122. ON m.`id` = rm.`menu_id`
  123. WHERE u.`empid` =? AND m.`path`=? ),0) IN (2,3))
  124. AND (p.id= ? OR IFNULL((SELECT MAX(r.`datarole`) FROM `user` u
  125. LEFT JOIN user_role ur
  126. ON ur.`user_id`= u.`id`
  127. LEFT JOIN role r
  128. ON r.`id` = ur.`role_id`
  129. LEFT JOIN role_menu rm
  130. ON r.`id` = rm.`role_id`
  131. LEFT JOIN menu m
  132. ON m.`id` = rm.`menu_id`
  133. WHERE u.`empid` = ? AND m.`path`=? ),0) = 3)) AND
  134. (p.`name`=? OR ?='现代牧业') AND (buk.upkeepCode LIKE CONCAT('%',?,'%')OR ?='')
  135. AND (e.`eqName` LIKE CONCAT('%',?,'%')OR ?='')
  136. AND (e.`eqCode` LIKE CONCAT('%',?,'%')OR ?='')
  137. AND (e.`departmentId`=? OR ?='')
  138. AND (buk.`plantime` >=? AND buk.`plantime`<=? OR ?='')
  139. AND buk.upkeepCode IS NOT NULL AND (
  140. IF (?=0,buk.flowCompeleted IN (2,3,5) ,
  141. IF(?=1,buk.flowCompeleted=7,buk.flowCompeleted IN (4,6,8))
  142. )
  143. OR ? = ''
  144. )) qq
  145. WHERE qq.statue=? OR ?=''
  146. ORDER BY qq.plantime DESC, qq.upkeepCode DESC