staff_hoggery_rel表:
    idx_staff_id :staff_id

    pigsty_info表:
    idx_co_hoggery_pigsty_status:hoggery_id, pigsty_attr_id, status


    feeding_document表:
    idx_pigsty:pigsty_id

    1. SELECT
    2. a.id,
    3. a.document_no,
    4. a.creator_id,
    5. a.creator_name,
    6. a.create_time,
    7. a.submitter_id,
    8. a.submitter_name,
    9. a.submit_time,
    10. a.reviewer_id,
    11. a.reviewer_name,
    12. a.review_time,
    13. a.updater_id,
    14. a.updater_name,
    15. a.update_time,
    16. a.canceler_id,
    17. a.canceler_name,
    18. a.cancel_time,
    19. a.start_date,
    20. a.end_date,
    21. a.pigsty_id,
    22. a.pigsty_name,
    23. a.num_of_pig,
    24. a.feed_quantity,
    25. a.feeders,
    26. a.remark,
    27. a.STATUS
    28. FROM
    29. feeding_document AS a
    30. INNER JOIN (
    31. SELECT
    32. t1.id
    33. FROM
    34. pigsty_info AS t1
    35. INNER JOIN
    36. ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2
    37. ON t1.pigsty_attr_id = t2.pigsty_attr_id
    38. AND t1.hoggery_id = t2.hoggery_id
    39. WHERE
    40. t1.STATUS = '1'
    41. ) AS b ON a.pigsty_id = b.id
    42. WHERE
    43. 1 = 1
    44. ORDER BY
    45. a.update_time DESC
    46. SELECT
    47. a.id,
    48. a.document_no,
    49. a.creator_id,
    50. a.creator_name,
    51. a.create_time,
    52. a.submitter_id,
    53. a.submitter_name,
    54. a.submit_time,
    55. a.reviewer_id,
    56. a.reviewer_name,
    57. a.review_time,
    58. a.updater_id,
    59. a.updater_name,
    60. a.update_time,
    61. a.canceler_id,
    62. a.canceler_name,
    63. a.cancel_time,
    64. a.start_date,
    65. a.end_date,
    66. a.pigsty_id,
    67. a.pigsty_name,
    68. a.num_of_pig,
    69. a.feed_quantity,
    70. a.feeders,
    71. a.remark,
    72. a.STATUS
    73. FROM
    74. feeding_document AS a
    75. WHERE
    76. 1 = 1
    77. and a.pigsty_id in (
    78. SELECT
    79. t1.id
    80. FROM
    81. pigsty_info AS t1
    82. INNER JOIN
    83. ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2
    84. ON t1.pigsty_attr_id = t2.pigsty_attr_id
    85. AND t1.hoggery_id = t2.hoggery_id
    86. WHERE
    87. t1.STATUS = '1'
    88. )
    89. ORDER BY
    90. a.update_time DESC

    immunization_document表:
    pigsty_id

    1. SELECT
    2. a.id,
    3. a.document_no,
    4. a.creator_id,
    5. a.creator_name,
    6. a.create_time,
    7. a.submitter_id,
    8. a.submitter_name,
    9. a.submit_time,
    10. a.reviewer_id,
    11. a.reviewer_name,
    12. a.review_time,
    13. a.updater_id,
    14. a.updater_name,
    15. a.update_time,
    16. a.canceler_id,
    17. a.canceler_name,
    18. a.cancel_time,
    19. a.immunization_date,
    20. a.pigsty_id,
    21. a.pigsty_name,
    22. a.num_of_pig,
    23. a.plan_id,
    24. a.plan_name,
    25. a.technicians,
    26. a.remark,
    27. a.STATUS
    28. FROM
    29. immunization_document AS a
    30. INNER JOIN (
    31. SELECT
    32. t1.id
    33. FROM
    34. pigsty_info AS t1
    35. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    36. AND t1.hoggery_id = t2.hoggery_id
    37. WHERE
    38. t1.STATUS = '1'
    39. ) AS b ON a.pigsty_id = b.id
    40. WHERE
    41. 1 = 1
    42. ORDER BY
    43. a.update_time DESC
    44. SELECT
    45. a.id,
    46. a.document_no,
    47. a.creator_id,
    48. a.creator_name,
    49. a.create_time,
    50. a.submitter_id,
    51. a.submitter_name,
    52. a.submit_time,
    53. a.reviewer_id,
    54. a.reviewer_name,
    55. a.review_time,
    56. a.updater_id,
    57. a.updater_name,
    58. a.update_time,
    59. a.canceler_id,
    60. a.canceler_name,
    61. a.cancel_time,
    62. a.immunization_date,
    63. a.pigsty_id,
    64. a.pigsty_name,
    65. a.num_of_pig,
    66. a.plan_id,
    67. a.plan_name,
    68. a.technicians,
    69. a.remark,
    70. a.STATUS
    71. FROM
    72. immunization_document AS a
    73. WHERE
    74. 1 = 1
    75. and a.pigsty_id in (
    76. SELECT
    77. t1.id
    78. FROM
    79. pigsty_info AS t1
    80. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    81. AND t1.hoggery_id = t2.hoggery_id
    82. WHERE
    83. t1.STATUS = '1'
    84. )
    85. ORDER BY
    86. a.update_time DESC

    health_document表: pigsty_id

    1. SELECT
    2. a.id,
    3. a.document_no,
    4. a.creator_id,
    5. a.creator_name,
    6. a.create_time,
    7. a.submitter_id,
    8. a.submitter_name,
    9. a.submit_time,
    10. a.reviewer_id,
    11. a.reviewer_name,
    12. a.review_time,
    13. a.updater_id,
    14. a.updater_name,
    15. a.update_time,
    16. a.canceler_id,
    17. a.canceler_name,
    18. a.cancel_time,
    19. a.start_date,
    20. a.end_date,
    21. a.pigsty_id,
    22. a.pigsty_name,
    23. a.num_of_pig,
    24. a.plan_id,
    25. a.plan_name,
    26. a.technicians,
    27. a.remark,
    28. a.STATUS
    29. FROM
    30. healthcare_document AS a
    31. INNER JOIN (
    32. SELECT
    33. t1.id
    34. FROM
    35. pigsty_info AS t1
    36. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    37. AND t1.hoggery_id = t2.hoggery_id
    38. WHERE
    39. t1.STATUS = '1'
    40. ) AS b ON a.pigsty_id = b.id
    41. WHERE
    42. 1 = 1
    43. ORDER BY
    44. a.update_time DESC
    45. SELECT
    46. a.id,
    47. a.document_no,
    48. a.creator_id,
    49. a.creator_name,
    50. a.create_time,
    51. a.submitter_id,
    52. a.submitter_name,
    53. a.submit_time,
    54. a.reviewer_id,
    55. a.reviewer_name,
    56. a.review_time,
    57. a.updater_id,
    58. a.updater_name,
    59. a.update_time,
    60. a.canceler_id,
    61. a.canceler_name,
    62. a.cancel_time,
    63. a.start_date,
    64. a.end_date,
    65. a.pigsty_id,
    66. a.pigsty_name,
    67. a.num_of_pig,
    68. a.plan_id,
    69. a.plan_name,
    70. a.technicians,
    71. a.remark,
    72. a.STATUS
    73. FROM
    74. healthcare_document AS a
    75. WHERE
    76. 1 = 1
    77. and a.pigsty_id in (
    78. SELECT
    79. t1.id
    80. FROM
    81. pigsty_info AS t1
    82. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    83. AND t1.hoggery_id = t2.hoggery_id
    84. WHERE
    85. t1.STATUS = '1'
    86. )
    87. ORDER BY
    88. a.update_time DESC

    deworming_pigsty_detail表:

    • pigsty_id
      1. SELECT
      2. a.id,
      3. a.document_no,
      4. a.creator_id,
      5. a.creator_name,
      6. a.create_time,
      7. a.submitter_id,
      8. a.submitter_name,
      9. a.submit_time,
      10. a.reviewer_id,
      11. a.reviewer_name,
      12. a.review_time,
      13. a.updater_id,
      14. a.updater_name,
      15. a.update_time,
      16. a.canceler_id,
      17. a.canceler_name,
      18. a.cancel_time,
      19. a.start_date,
      20. a.end_date,
      21. a.num_of_pigsty,
      22. a.plan_id,
      23. a.plan_name,
      24. a.technicians,
      25. a.remark,
      26. a.STATUS
      27. FROM
      28. deworming_document AS a
      29. INNER JOIN (
      30. SELECT
      31. t3.document_id
      32. FROM
      33. deworming_pigsty_detail AS t3
      34. INNER JOIN (
      35. SELECT
      36. t1.id
      37. FROM
      38. pigsty_info AS t1
      39. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1410503535148199937 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
      40. AND t1.hoggery_id = t2.hoggery_id
      41. WHERE
      42. t1.STATUS = '1'
      43. ) AS t4 ON t4.id = t3.pigsty_id
      44. GROUP BY
      45. t3.document_id
      46. ) AS b ON a.id = b.document_id
      47. WHERE
      48. 1 = 1
      49. ORDER BY
      50. a.update_time DESC SELECT
      51. a.id,
      52. a.document_no,
      53. a.creator_id,
      54. a.creator_name,
      55. a.create_time,
      56. a.submitter_id,
      57. a.submitter_name,
      58. a.submit_time,
      59. a.reviewer_id,
      60. a.reviewer_name,
      61. a.review_time,
      62. a.updater_id,
      63. a.updater_name,
      64. a.update_time,
      65. a.canceler_id,
      66. a.canceler_name,
      67. a.cancel_time,
      68. a.start_date,
      69. a.end_date,
      70. a.num_of_pigsty,
      71. a.plan_id,
      72. a.plan_name,
      73. a.technicians,
      74. a.remark,
      75. a.STATUS
      76. FROM
      77. deworming_document AS a
      78. WHERE
      79. 1 = 1
      80. AND a.id IN (
      81. SELECT
      82. t3.document_id
      83. FROM
      84. deworming_pigsty_detail AS t3
      85. INNER JOIN (
      86. SELECT
      87. t1.id
      88. FROM
      89. pigsty_info AS t1
      90. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1410503535148199937 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
      91. AND t1.hoggery_id = t2.hoggery_id
      92. WHERE
      93. t1.STATUS = '1'
      94. ) AS t4 ON t4.id = t3.pigsty_id
      95. GROUP BY
      96. t3.document_id
      97. )
      98. ORDER BY
      99. a.update_time DESC

    disinfecting_pigsty_detail表
    pigsty_id

    1. SELECT
    2. a.id,
    3. a.document_no,
    4. a.creator_id,
    5. a.creator_name,
    6. a.create_time,
    7. a.submitter_id,
    8. a.submitter_name,
    9. a.submit_time,
    10. a.reviewer_id,
    11. a.reviewer_name,
    12. a.review_time,
    13. a.updater_id,
    14. a.updater_name,
    15. a.update_time,
    16. a.canceler_id,
    17. a.canceler_name,
    18. a.cancel_time,
    19. a.start_date,
    20. a.end_date,
    21. a.num_of_pigsty,
    22. a.plan_id,
    23. a.plan_name,
    24. a.technicians,
    25. a.remark,
    26. a.STATUS
    27. FROM
    28. disinfecting_document AS a
    29. INNER JOIN (
    30. SELECT
    31. t3.document_id
    32. FROM
    33. disinfecting_pigsty_detail AS t3
    34. INNER JOIN (
    35. SELECT
    36. t1.id
    37. FROM
    38. pigsty_info AS t1
    39. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    40. AND t1.hoggery_id = t2.hoggery_id
    41. WHERE
    42. t1.STATUS = '1'
    43. ) AS t4 ON t4.id = t3.pigsty_id
    44. GROUP BY
    45. t3.document_id
    46. ) AS b ON a.id = b.document_id
    47. WHERE
    48. 1 = 1
    49. ORDER BY
    50. a.update_time DESC

    monitoring_document表:
    pigsty_id

    1. SELECT
    2. a.id,
    3. a.document_no,
    4. a.creator_id,
    5. a.creator_name,
    6. a.create_time,
    7. a.submitter_id,
    8. a.submitter_name,
    9. a.submit_time,
    10. a.reviewer_id,
    11. a.reviewer_name,
    12. a.review_time,
    13. a.updater_id,
    14. a.updater_name,
    15. a.update_time,
    16. a.canceler_id,
    17. a.canceler_name,
    18. a.cancel_time,
    19. a.start_date,
    20. a.end_date,
    21. a.pigsty_id,
    22. a.pigsty_name,
    23. a.num_of_pig,
    24. a.program_id,
    25. a.program_name,
    26. a.remark,
    27. a.STATUS
    28. FROM
    29. monitoring_document AS a
    30. INNER JOIN (
    31. SELECT
    32. t1.id
    33. FROM
    34. pigsty_info AS t1
    35. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1409455042715512834 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    36. AND t1.hoggery_id = t2.hoggery_id
    37. WHERE
    38. t1.STATUS = '1'
    39. ) AS b ON a.pigsty_id = b.id
    40. WHERE
    41. 1 = 1
    42. ORDER BY
    43. a.update_time DESC

    diagnosing_document表:
    status update_time pigsty_id

    1. SELECT
    2. a.id,
    3. a.document_no,
    4. a.creator_id,
    5. a.creator_name,
    6. a.create_time,
    7. a.submitter_id,
    8. a.submitter_name,
    9. a.submit_time,
    10. a.reviewer_id,
    11. a.reviewer_name,
    12. a.review_time,
    13. a.updater_id,
    14. a.updater_name,
    15. a.update_time,
    16. a.canceler_id,
    17. a.canceler_name,
    18. a.cancel_time,
    19. a.diagnosis_date,
    20. a.pigsty_id,
    21. a.pigsty_name,
    22. a.num_of_pig,
    23. a.symptom,
    24. a.disease_id,
    25. a.disease_name,
    26. a.treatment,
    27. a.start_date,
    28. a.end_date,
    29. a.remark,
    30. a.STATUS
    31. FROM
    32. diagnosing_document AS a
    33. INNER JOIN (
    34. SELECT
    35. t1.id
    36. FROM
    37. pigsty_info AS t1
    38. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1410045881586085889 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    39. AND t1.hoggery_id = t2.hoggery_id
    40. WHERE
    41. t1.STATUS = '1'
    42. ) AS b ON a.pigsty_id = b.id
    43. WHERE
    44. 1 = 1
    45. and `status` =4
    46. and update_time >= '1970-01-01'
    47. and update_time <=now()
    48. ORDER BY
    49. a.update_time DESC

    treatment_document

    1. SELECT
    2. a.id,
    3. a.document_no,
    4. a.creator_id,
    5. a.creator_name,
    6. a.create_time,
    7. a.submitter_id,
    8. a.submitter_name,
    9. a.submit_time,
    10. a.reviewer_id,
    11. a.reviewer_name,
    12. a.review_time,
    13. a.updater_id,
    14. a.updater_name,
    15. a.update_time,
    16. a.canceler_id,
    17. a.canceler_name,
    18. a.cancel_time,
    19. a.start_date,
    20. a.end_date,
    21. a.pigsty_id,
    22. a.pigsty_name,
    23. a.disease_name,
    24. a.prescription_id,
    25. a.prescription_name,
    26. a.num_of_pig,
    27. a.technicians,
    28. a.remark,
    29. a.STATUS
    30. FROM
    31. treatment_document AS a
    32. INNER JOIN (
    33. SELECT
    34. t1.id
    35. FROM
    36. pigsty_info AS t1
    37. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1410045881586085889 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    38. AND t1.hoggery_id = t2.hoggery_id
    39. WHERE
    40. t1.STATUS = '1'
    41. ) AS b ON a.pigsty_id = b.id
    42. WHERE
    43. 1 = 1
    44. AND a.update_time >= '1970-01-01'
    45. AND a.update_time <= now()
    46. AND a.STATUS = '3'
    47. ORDER BY
    48. a.update_time DESC

    transfer_document表:

    1. SELECT
    2. id,
    3. document_no,
    4. creator_id,
    5. creator_name,
    6. create_time,
    7. submitter_id,
    8. submitter_name,
    9. submit_time,
    10. out_reviewer_id,
    11. out_reviewer_name,
    12. out_review_time,
    13. into_reviewer_id,
    14. into_reviewer_name,
    15. into_review_time,
    16. updater_id,
    17. updater_name,
    18. update_time,
    19. canceler_id,
    20. canceler_name,
    21. cancel_time,
    22. pig_type,
    23. transfer_date,
    24. out_pigsty_id,
    25. out_pigsty_name,
    26. num_of_pig,
    27. into_pigsty_id,
    28. into_pigsty_name,
    29. total_weight,
    30. reason,
    31. remark,
    32. STATUS
    33. FROM
    34. transfer_document
    35. WHERE
    36. 1 = 1
    37. AND (
    38. out_pigsty_id IN (
    39. SELECT
    40. t1.id
    41. FROM
    42. pigsty_info AS t1
    43. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1410045881586085889 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    44. AND t1.hoggery_id = t2.hoggery_id
    45. WHERE
    46. t1.STATUS = '1'
    47. )
    48. OR into_pigsty_id IN (
    49. SELECT
    50. t1.id
    51. FROM
    52. pigsty_info AS t1
    53. INNER JOIN ( SELECT t.hoggery_id, t.pigsty_attr_id FROM staff_hoggery_rel AS t WHERE t.staff_id = 1410045881586085889 ) AS t2 ON t1.pigsty_attr_id = t2.pigsty_attr_id
    54. AND t1.hoggery_id = t2.hoggery_id
    55. WHERE
    56. t1.STATUS = '1'
    57. )
    58. )
    59. AND update_time <= now()
    60. AND STATUS IN ( '3','4' )
    61. ORDER BY
    62. update_time DESC