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
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.feed_quantity,
a.feeders,
a.remark,
a.STATUS
FROM
feeding_document AS a
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS b ON a.pigsty_id = b.id
WHERE
1 = 1
ORDER BY
a.update_time DESC
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.feed_quantity,
a.feeders,
a.remark,
a.STATUS
FROM
feeding_document AS a
WHERE
1 = 1
and a.pigsty_id in (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
)
ORDER BY
a.update_time DESC
immunization_document表:
pigsty_id
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.immunization_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.plan_id,
a.plan_name,
a.technicians,
a.remark,
a.STATUS
FROM
immunization_document AS a
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS b ON a.pigsty_id = b.id
WHERE
1 = 1
ORDER BY
a.update_time DESC
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.immunization_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.plan_id,
a.plan_name,
a.technicians,
a.remark,
a.STATUS
FROM
immunization_document AS a
WHERE
1 = 1
and a.pigsty_id in (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
)
ORDER BY
a.update_time DESC
health_document表: pigsty_id
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.plan_id,
a.plan_name,
a.technicians,
a.remark,
a.STATUS
FROM
healthcare_document AS a
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS b ON a.pigsty_id = b.id
WHERE
1 = 1
ORDER BY
a.update_time DESC
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.plan_id,
a.plan_name,
a.technicians,
a.remark,
a.STATUS
FROM
healthcare_document AS a
WHERE
1 = 1
and a.pigsty_id in (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
)
ORDER BY
a.update_time DESC
deworming_pigsty_detail表:
- pigsty_id
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.num_of_pigsty,
a.plan_id,
a.plan_name,
a.technicians,
a.remark,
a.STATUS
FROM
deworming_document AS a
INNER JOIN (
SELECT
t3.document_id
FROM
deworming_pigsty_detail AS t3
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS t4 ON t4.id = t3.pigsty_id
GROUP BY
t3.document_id
) AS b ON a.id = b.document_id
WHERE
1 = 1
ORDER BY
a.update_time DESC SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.num_of_pigsty,
a.plan_id,
a.plan_name,
a.technicians,
a.remark,
a.STATUS
FROM
deworming_document AS a
WHERE
1 = 1
AND a.id IN (
SELECT
t3.document_id
FROM
deworming_pigsty_detail AS t3
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS t4 ON t4.id = t3.pigsty_id
GROUP BY
t3.document_id
)
ORDER BY
a.update_time DESC
disinfecting_pigsty_detail表
pigsty_id
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.num_of_pigsty,
a.plan_id,
a.plan_name,
a.technicians,
a.remark,
a.STATUS
FROM
disinfecting_document AS a
INNER JOIN (
SELECT
t3.document_id
FROM
disinfecting_pigsty_detail AS t3
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS t4 ON t4.id = t3.pigsty_id
GROUP BY
t3.document_id
) AS b ON a.id = b.document_id
WHERE
1 = 1
ORDER BY
a.update_time DESC
monitoring_document表:
pigsty_id
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.program_id,
a.program_name,
a.remark,
a.STATUS
FROM
monitoring_document AS a
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS b ON a.pigsty_id = b.id
WHERE
1 = 1
ORDER BY
a.update_time DESC
diagnosing_document表:
status update_time pigsty_id
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.diagnosis_date,
a.pigsty_id,
a.pigsty_name,
a.num_of_pig,
a.symptom,
a.disease_id,
a.disease_name,
a.treatment,
a.start_date,
a.end_date,
a.remark,
a.STATUS
FROM
diagnosing_document AS a
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS b ON a.pigsty_id = b.id
WHERE
1 = 1
and `status` =4
and update_time >= '1970-01-01'
and update_time <=now()
ORDER BY
a.update_time DESC
treatment_document
SELECT
a.id,
a.document_no,
a.creator_id,
a.creator_name,
a.create_time,
a.submitter_id,
a.submitter_name,
a.submit_time,
a.reviewer_id,
a.reviewer_name,
a.review_time,
a.updater_id,
a.updater_name,
a.update_time,
a.canceler_id,
a.canceler_name,
a.cancel_time,
a.start_date,
a.end_date,
a.pigsty_id,
a.pigsty_name,
a.disease_name,
a.prescription_id,
a.prescription_name,
a.num_of_pig,
a.technicians,
a.remark,
a.STATUS
FROM
treatment_document AS a
INNER JOIN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
) AS b ON a.pigsty_id = b.id
WHERE
1 = 1
AND a.update_time >= '1970-01-01'
AND a.update_time <= now()
AND a.STATUS = '3'
ORDER BY
a.update_time DESC
transfer_document表:
SELECT
id,
document_no,
creator_id,
creator_name,
create_time,
submitter_id,
submitter_name,
submit_time,
out_reviewer_id,
out_reviewer_name,
out_review_time,
into_reviewer_id,
into_reviewer_name,
into_review_time,
updater_id,
updater_name,
update_time,
canceler_id,
canceler_name,
cancel_time,
pig_type,
transfer_date,
out_pigsty_id,
out_pigsty_name,
num_of_pig,
into_pigsty_id,
into_pigsty_name,
total_weight,
reason,
remark,
STATUS
FROM
transfer_document
WHERE
1 = 1
AND (
out_pigsty_id IN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
)
OR into_pigsty_id IN (
SELECT
t1.id
FROM
pigsty_info AS t1
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
AND t1.hoggery_id = t2.hoggery_id
WHERE
t1.STATUS = '1'
)
)
AND update_time <= now()
AND STATUS IN ( '3','4' )
ORDER BY
update_time DESC