select a.id, a.person_id, p.name as person_name, a.chronic_disease_id, c.disease_name as chronic_disease_name, a.plan_name, a.medicine_id, a.medicine_name, a.specification, a.dosage_per_time, a.dosage_unit, a.frequency_type, a.frequency_config, a.time_slots, a.start_date, a.end_date, a.remind_enabled, a.remind_advance_min, a.notify_family, a.family_member_ids, a.status, a.create_time, (select count(1) from medication_task t where t.plan_id = a.id and t.del_flag = 0 and t.planned_date = current_date) as today_total, (select count(1) from medication_task t where t.plan_id = a.id and t.del_flag = 0 and t.planned_date = current_date and t.status = 1) as today_completed from medication_plan a left join health_person p on a.person_id = p.id left join chronic_disease_record c on a.chronic_disease_id = c.id insert into medication_plan person_id, chronic_disease_id, plan_name, medicine_id, medicine_name, specification, dosage_per_time, dosage_unit, frequency_type, frequency_config, time_slots, start_date, end_date, remind_enabled, remind_advance_min, notify_family, family_member_ids, status, create_by, create_time, remark, del_flag, #{personId}, #{chronicDiseaseId}, #{planName}, #{medicineId}, #{medicineName}, #{specification}, #{dosagePerTime}, #{dosageUnit}, #{frequencyType}, #{frequencyConfig, typeHandler=com.intc.common.core.handler.JsonNodeTypeHandler}, #{timeSlots, typeHandler=com.intc.common.core.handler.JsonNodeTypeHandler}, #{startDate}, #{endDate}, #{remindEnabled}, #{remindAdvanceMin}, #{notifyFamily}, #{familyMemberIds, typeHandler=com.intc.common.core.handler.JsonNodeTypeHandler}, #{status}, #{createBy}, #{createTime}, #{remark}, 0, update medication_plan person_id = #{personId}, chronic_disease_id = #{chronicDiseaseId}, plan_name = #{planName}, medicine_id = #{medicineId}, medicine_name = #{medicineName}, specification = #{specification}, dosage_per_time = #{dosagePerTime}, dosage_unit = #{dosageUnit}, frequency_type = #{frequencyType}, frequency_config = #{frequencyConfig, typeHandler=com.intc.common.core.handler.JsonNodeTypeHandler}, time_slots = #{timeSlots, typeHandler=com.intc.common.core.handler.JsonNodeTypeHandler}, start_date = #{startDate}, end_date = #{endDate}, remind_enabled = #{remindEnabled}, remind_advance_min = #{remindAdvanceMin}, notify_family = #{notifyFamily}, family_member_ids = #{familyMemberIds, typeHandler=com.intc.common.core.handler.JsonNodeTypeHandler}, status = #{status}, update_by = #{updateBy}, update_time = #{updateTime}, remark = #{remark}, where id = #{id} delete from medication_plan where id = #{id} delete from medication_plan where id in #{id} update medication_plan set del_flag = 1 where id = #{id} update medication_plan set del_flag = 1 where id in #{id}