getBigupkeepListAPP.sql 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. SELECT
  2. qq.*
  3. FROM
  4. (SELECT
  5. IFNULL(bpa1.cou,0) laidcou,
  6. buk.id,
  7. buk.`eqId`,
  8. buk.pushbackId,
  9. buk.bigupkeeptemplateId,
  10. CONCAT(
  11. '名称:',
  12. but.`upkeepName`,
  13. '|保养级别:',
  14. but.`upkeepLevel`
  15. ) upNameLevel,
  16. buk.`upkeepCode`,
  17. buk.workflowNote,
  18. buk.scores,
  19. buk.chargeDate,
  20. buk.useChargeDate,
  21. buk.finishedTime,
  22. em1.`empname` upkeepPerson,
  23. em2.`empname` useChargePerson,
  24. em3.`empname` chargePerson,
  25. em4.empname deptChargePerson,ifnull( buk.useEmpId, e.employeeId) useEmpId,ifnull(em5.empname ,em.empname) useEmpName,
  26. buk.deptChargeDate,
  27. buk.deptChargeId,
  28. IFNULL(em.`empname`,employeName) employeName,
  29. e.employeeId,
  30. e.`departmentId`,
  31. buk.upkeepPerson upkeepPersonId,
  32. e.`eqCode`,
  33. e.`eqName`,
  34. e.`specification`,
  35. p.`name` pastureName,
  36. d.`name` departmentName,
  37. IF(
  38. buk.`flowCompeleted` = 1 AND DATE_FORMAT(NOW(), '%Y-%m-%d') = buk.`plantime` or (buk.pushbackId<>0 and DATE_SUB(DATE_FORMAT( buk.`plantime`,'%Y-%m-%d'),INTERVAL -1 DAY)=DATE_FORMAT(NOW(), '%Y-%m-%d')AND buk.`flowCompeleted` = 1 AND buk.`flowCompeleted` = 1),
  39. 1,
  40. if( buk.`flowCompeleted` = 1 AND DATE_FORMAT(NOW(), '%Y-%m-%d') > buk.`plantime`,0,2
  41. )
  42. ) statue,
  43. IF(bpa.cou IS NULL,'未领用','已领用') LYStatue,
  44. IF(rf.cou IS NULL,'未录入','已录入') LRStatue,
  45. buk.flowCompeleted SHStatue,
  46. (select ifnull(device,0) from `user` where empId = ? ) isVideoBtnShow, # 录制视屏按钮
  47. case
  48. when (select id from video where upkeepId =buk.id) is null then '未录制'
  49. when (select id from video where upkeepId =162283 and endRecord =2 ) is not null then '录制中'
  50. when (select id from video where upkeepId =buk.id and newCreateTime=createTime and location <>'') is not null then '已录制'
  51. else '已录制上传中'
  52. end as videoTxt,# 录制状态
  53. ifnull((select location from video where upkeepId =buk.id),'') videoPath, # 录制地址
  54. (select deviceId from device_information where empId = ?) deviceId,# 设备id
  55. (select `password` from device_information where empId = ?) pwd, #密码
  56. (select uId from device_information where empId = ?) uId, # uid
  57. ifnull((select DATE_FORMAT(createTime,'%Y-%m-%d') from video where upkeepId =buk.id),'') videoTime,
  58. buk.`plantime`
  59. FROM
  60. bigupkeep buk
  61. INNER JOIN equipment e
  62. ON buk.`eqId` = e.`id`
  63. INNER JOIN pasture P
  64. ON P.`id` = E.`pastureId`
  65. LEFT JOIN department d
  66. ON e.`departmentId` = d.`id`
  67. LEFT JOIN emp em
  68. ON em.id = e.employeeId
  69. LEFT JOIN emp em1
  70. ON em1.id = buk.upkeepPerson
  71. LEFT JOIN emp em2
  72. ON em2.id = buk.useChargeId
  73. LEFT JOIN emp em3
  74. ON em3.id = buk.chargeId
  75. LEFT JOIN emp em4
  76. ON em4.id = buk.deptChargeId
  77. LEFT JOIN emp em5
  78. ON em5.id = buk.useEmpId
  79. LEFT JOIN bigupkeeptemplate but
  80. ON but.id = buk.bigupkeeptemplateId
  81. LEFT JOIN (SELECT RUCode,COUNT(id)cou FROM bigpartapply GROUP BY RUCode ) bpa
  82. ON bpa.`RUCode` = buk.`upkeepCode`
  83. LEFT JOIN (SELECT repairCode,COUNT(id)cou FROM refuse GROUP BY repairCode)rf
  84. ON rf.`repairCode` = buk.`upkeepCode`
  85. LEFT JOIN (SELECT RUCode,COUNT(id)cou FROM bigpartapply WHERE statue =0 and (SHStatus in (2,3,5,7,9)) GROUP BY RUCode ) bpa1
  86. ON bpa1.`RUCode` = buk.`upkeepCode`
  87. WHERE
  88. buk.`upkeepPerson` = ? AND buk.`pastureId` =? and
  89. buk.upkeepCode IS NOT NULL
  90. ) qq
  91. WHERE IF(?=0,qq.SHStatue IN(4,6) OR (DATE_FORMAT(NOW(), '%Y-%m-%d') = qq.`plantime` AND qq.SHStatue = 1 )
  92. OR (DATE_FORMAT(DATE_ADD(NOW(),INTERVAL -1 DAY), '%Y-%m-%d') = qq.`plantime` AND qq.SHStatue = 1 )
  93. OR (qq.pushbackId <>0 AND DATE_SUB(DATE_FORMAT( qq.`plantime`,'%Y-%m-%d'),INTERVAL -1 DAY)=DATE_FORMAT(NOW(), '%Y-%m-%d') AND qq.SHStatue = 1) ,qq.SHStatue > 1)
  94. ORDER BY qq.plantime DESC