getPartApplyByBig.sql 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. SELECT
  2. CONCAT('uploads/thumbnail/',ep.`picpath`,'/',ep.`newpicname`) picpath,
  3. CONCAT('uploads/image/',ep.`picpath`,'/',ep.`newpicname`) srcpath,
  4. IF (bpa.`applyType`='0','非维保',
  5. IF (bpa.`applyType`='1','维修','保养')) applyType,
  6. pa.pastureId,
  7. pr.`id`,
  8. pa.id paid,
  9. pa.`partCode`,
  10. pa.`partId`,
  11. pr.`brandId`,
  12. TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM pa.`price`))) price,
  13. pa.`specification`,
  14. ROUND(pa.amount,2) amount,
  15. TRIM(TRAILING '.' FROM (TRIM(TRAILING '0' FROM pa.`sumPrice`))) sumPrice ,
  16. pa.`eqCode`,
  17. pa.`eqName`,
  18. pa.`providerId`,
  19. pa.`useTypeV`,
  20. pa.`note`,
  21. pa.partName,
  22. pr.reportery,
  23. pr.`location`,
  24. pr.`locationId`,
  25. pr.`reportery`,
  26. pr.`unit`,
  27. pr.contractId,
  28. pr.`brand`,
  29. pv.providerName
  30. FROM
  31. partapply pa
  32. INNER JOIN bigpartapply bpa
  33. ON pa.`bigId` = bpa.`id`
  34. LEFT JOIN part_repertory pr
  35. ON IF(pa.`contractId`='' OR pa.`contractId` IS NULL ,(pa.`partCode` = pr.`partCode` AND pa.`providerId` = pr.`providerId` AND bpa.pastureId = pr.pastureId AND (pr. reportery>0 OR (SELECT bc.`statue` FROM contract c
  36. INNER JOIN bigcontract bc
  37. ON c.`bigId` = bc.`id`
  38. WHERE c.id = pr.`contractId`)=1 )
  39. # 新添加的
  40. and( (pa.`locationId`='' or pa.`locationId` is null) or pa.`locationId`= pr.`locationId` )
  41. #####
  42. ),(pa.`contractId`=pr.`contractId` AND pa.`brandid`=pr.`brandid`)
  43. # 新添加的
  44. and( (pa.`locationId` is null) or (pr.`locationId` is null) or (pa.`locationId`= pr.`locationId`) )
  45. #####
  46. )
  47. LEFT JOIN provider pv
  48. ON (pv.`id` = pr.`providerId` or pv.`id` = pa.`providerId`)
  49. LEFT JOIN parts ps
  50. ON ps.id = pa.partId
  51. LEFT JOIN eq_pic ep
  52. ON ep.id = ps.picpath
  53. WHERE pa.`bigId` = ?
  54. and
  55. (
  56. pa.pastureId =18 or
  57. (select pastureId from warehouse where id = pr.`locationId`)=?)
  58. ORDER BY partCode