v0002_alter_bigpartpurchase.sql 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. ALTER TABLE `bigpartpurchase`
  2. ADD COLUMN `purchase_type` tinyint(1) unsigned NOT NULL DEFAULT '0' COMMENT '申购类型 0 无效 1 暂估 2 垫付',
  3. ADD COLUMN `funder_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '垫资人id';
  4. ALTER TABLE `bigpartuse` ADD COLUMN greenFodderNumber varchar(255) NOT NULL DEFAULT '' COMMENT '青贮单号';
  5. # SELECT * FROM apisql WHERE sqlname = 'insertBigPartUse'
  6. INSERT INTO bigpartuse (
  7. pastureId,
  8. departmentId,
  9. useForm,
  10. listType,
  11. applicatId,
  12. receiveTime,
  13. empId,
  14. useType,
  15. oddCode,
  16. note,
  17. greenFodderNumber
  18. ) VALUES ( ?,(select departmentId from bigpartapply where applyCode = ? ),?,?,?,?,?,?,?,?,?)
  19. # pastureId,oddCode,useForm,listType,applicatId,receiveTime,empId,useType,oddCode,note,greenFodderNumber
  20. # SELECT * FROM apisql WHERE sqlname = 'getpartpurchaseList'
  21. SELECT
  22. bpp.providerId,
  23. pr.providerName,
  24. bpp.`buyStatu`,
  25. DATE_FORMAT(bpp.`CGChargedate`,'%Y-%m-%d %H:%i:%s') CGChargedate,
  26. bpp.`CGChargeId`,
  27. DATE_FORMAT(bpp.`chargeDate`,'%Y-%m-%d %H:%i:%s') chargeDate,
  28. bpp.`chargeId`,
  29. bpp.`createTime`,
  30. bpp.`departmentId`,
  31. bpp.`employeId`,
  32. bpp.`flowCompeleted`,
  33. bpp.`flowworkNote`,
  34. bpp.`id`,
  35. bpp.`isUrgent`,
  36. DATE_FORMAT(bpp.`KGChargedate`,'%Y-%m-%d %H:%i:%s') KGChargedate ,
  37. bpp.`KGChargeId`,
  38. bpp.`orderNumber`,
  39. bpp.`pastureId`,
  40. bpp.`statue`,
  41. bpp.`workflowId`,
  42. bpp.`workflowNote`,
  43. bpp.purchase_type, # 这次加字段
  44. bpp.funder_id, # 这次加字段
  45. p.`name` pastureName,
  46. e.empname ,
  47. e6.empname funderName, # 这次加字段
  48. e1.empname KGChargePerson,
  49. e2.empname chargePerson,
  50. e3.empname CGChargePerson,
  51. d.`name` AS departmentName,
  52. DATE_FORMAT(bpp.createTime, '%Y-%m-%d') inputTime,
  53. e4.empname equipmentPerson,
  54. bpp.equipment,
  55. DATE_FORMAT(bpp.equipmentdate,'%Y-%m-%d %H:%i:%s') equipmentdate ,
  56. e5.empname fieldPerson,
  57. DATE_FORMAT(bpp.fielddate,'%Y-%m-%d %H:%i:%s') fielddate,
  58. if((select sum(price*amount) from partpurchase where bigid = bpp.id )> 5000 ,1,
  59. if((select sum(if(price>3000,1,0)) from partpurchase where bigid = bpp.id)>0,1,0)) as priceClass
  60. FROM
  61. bigpartpurchase bpp
  62. LEFT JOIN pasture p
  63. ON p.id = bpp.pastureId
  64. LEFT JOIN emp e
  65. ON e.id = bpp.employeId
  66. LEFT JOIN department d
  67. ON d.id = bpp.departmentId
  68. LEFT JOIN emp e1
  69. ON e1.id = bpp.KGChargeId
  70. LEFT JOIN emp e2
  71. ON e2.id = bpp.chargeId
  72. LEFT JOIN emp e3
  73. ON e3.id = bpp.CGChargeId
  74. LEFT JOIN emp e4
  75. ON e4.id = bpp.equipment
  76. LEFT JOIN emp e5
  77. ON e5.id = bpp.field
  78. LEFT JOIN emp e6
  79. ON e6.id = bpp.funder_id
  80. LEFT JOIN provider pr
  81. ON pr.id = bpp.providerId
  82. WHERE
  83. ((bpp.employeId = ? 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 (bpp.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 bpp.employeId = ? 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))
  134. AND
  135. (
  136. bpp.orderNumber LIKE CONCAT("%", ?, "%")
  137. OR ? = ''
  138. )
  139. AND (
  140. p.`name` = ?
  141. OR ? = '现代牧业'
  142. )
  143. AND (
  144. bpp.departmentId = ?
  145. OR ? = ''
  146. )AND (
  147. (bpp.createTime >= ? AND bpp.createTime <= ? )
  148. OR ? = ''
  149. )
  150. AND (
  151. IF (?=0,bpp.statue IN (2,3,5) ,
  152. IF(?=1,bpp.statue=7,bpp.statue IN (4,6,8))
  153. )
  154. OR ? = ''
  155. )
  156. AND
  157. (
  158. e.empname LIKE CONCAT("%", ?, "%")
  159. OR ? = ''
  160. )
  161. AND (bpp.purchase_type = ? OR ? = '')
  162. ORDER BY bpp.id DESC
  163. ## loginId,loginId,menu,loginpastureId,loginId,menu,loginpastureId,logindeptId,loginId,loginId,menu,loginpastureId,loginId,menu,orderNumber ,orderNumber ,pastureName,pastureName,departmentId ,departmentId,startTime,stopTime,startTime,stuteSH,stuteSH,stuteSH,empName,empName,purchase_type