我要预约

偶尔家人会有预约医生的需要,比如四川华西,于是...

没有技术含量,稍微用点时间。程序员的人生就是用代码改变生活点滴。

要实现声光电也是可以的。实现了在家里服务器中语音提醒,以及在企业微信号中提示信息

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net/http"
	"os"
	"os/exec"
	"strconv"
	"time"

	"github.com/tidwall/gjson"
)

func main() {
	fmt.Println("获取数据中...")
	doctorID := "5618"
	if len(os.Args) > 1 {
		doctorID = os.Args[1]
	}
	resp, _ := http.Get(fmt.Sprintf("http://www.cd120.com/doctorScheduleRecond.jspx?doctorCode=%s", doctorID))
	//resp, _ := http.Get("http://www.cd120.com/doctorScheduleRecond.jspx?doctorCode=0544")
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println("数据分析中...")
	doctorName := gjson.Get(string(body), "data.vo.doctorName")
	value := gjson.Get(string(body), "data.vo.scheduleStrList")
	fmt.Println(doctorName, "-----------------------------")
	for i := 0; i < 10; i++ {
		v := value.Get(strconv.Itoa(i))
		if v.String() != "" {
			amType := v.Get("amType").String()
			pmType := v.Get("pmType").String()
			serviceDate := v.Get("serviceDate").String()
			weekDays := v.Get("weekDays").String()

			fmt.Println(fmt.Sprintf("%s %s   \t上午:%-7s \t下午:%-7s", serviceDate, weekDays, amType, pmType))
			if amType == "可预约" {
				info := fmt.Sprintf("%s医生%s上午可预约了", doctorName, serviceDate)
				Shell("qywx " + info)  //企业微信发信息
				for m := 0; m < 3; m++ { //让它多提示几遍
					Shell("say " + info) //语音提示
					time.Sleep(1 * time.Second)
				}
			}
			if pmType == "可预约" {
				info := fmt.Sprintf("%s医生%s下午可预约了", doctorName, serviceDate)
				Shell("qywx " + info)
				for m := 0; m < 3; m++ {
					Shell("say " + info)
					time.Sleep(1 * time.Second)
				}
			}

		}
	}
}

// 运行命令
func Shell(cmdStr string) string {
	cmd := exec.Command("/bin/bash", "-c", cmdStr)
	var out bytes.Buffer
	cmd.Stdout = &out
	cmd.Run()

	ret := out.String()
	return ret
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是 MySQL 语言的代码示例: ``` CREATE TRIGGER `appointment_trigger` BEFORE INSERT ON `appointment_table` FOR EACH ROW BEGIN DECLARE v_doctor_id INT; DECLARE v_appointment_time DATETIME; DECLARE v_weekday INT; DECLARE v_time_slot INT; DECLARE v_max_appointments INT; DECLARE v_current_appointments INT; SELECT doctor_id, appointment_time, max_appointments, current_appointments INTO v_doctor_id, v_appointment_time, v_max_appointments, v_current_appointments FROM doctor_schedule WHERE schedule_time = DATE_FORMAT(NEW.appointment_time, '%W %H:%i'); SET v_weekday = WEEKDAY(v_appointment_time); SET v_time_slot = TIME_FORMAT(v_appointment_time, '%H%i'); IF v_current_appointments >= v_max_appointments THEN SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Doctor is fully booked at this time'; ELSE UPDATE doctor_schedule SET current_appointments = current_appointments + 1 WHERE doctor_id = v_doctor_id AND schedule_time = DATE_FORMAT(NEW.appointment_time, '%W %H:%i'); INSERT INTO appointment_table(doctor_id, patient_id, appointment_time, weekday, time_slot) VALUES(v_doctor_id, NEW.patient_id, v_appointment_time, v_weekday, v_time_slot); END IF; END; ``` 解释一下代码的逻辑: 1. 创建一个名为 `appointment_trigger` 的触发器,在每次向 `appointment_table` 插入新数据之前触发。 2. 声明一些变量,用于存储医生 ID、预约时间、周几、时间段、最大预约人数和当前预约人数。 3. 从 `doctor_schedule` 表中查询出符合预约时间的医生 ID、排班时间、最大预约人数和当前预约人数,存储到变量中。 4. 计算预约时间的周几和时间段,存储到变量中。 5. 检查当前预约人数是否已经达到最大预约人数。 6. 如果医生已经预约满了,则抛出一个 SQLSTATE 异常,提示医生已经预约满了。 7. 如果医生还有预约名额,则更新 `doctor_schedule` 表中的当前预约人数,插入一条新数据到 `appointment_table` 表中。 这样,当患者预约时,触发器会自动调用医生排班表,判断患者预约的日期是周几的几点,并且查看预约表,查看此时间段医生是否还有剩余预约名额。如果医生还有剩余预约名额,则会将预约信息写入预约表中,并更新医生排班表中的预约人数;否则,会抛出一个异常提示医生已经预约满了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值