package com.yihu.wlyy.task;

import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.service.common.SMSService;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

/**
 * 居民微信关注提醒
 * <p>
 * Created by lyr-pc on 2017/1/16.
 */
public class RemindFocusWechatTask implements Runnable {

    List<Map<String, Object>> patients;

    Doctor doctor;

    /**
     * 构造函数
     *
     * @param patients 居民列表
     */
    public RemindFocusWechatTask(List<Map<String, Object>> patients, Doctor doctor) {
        this.patients = patients;
        this.doctor = doctor;
    }

    @Override
    public void run() {
        for (Map<String, Object> p : patients) {
            try {
                if (p.get("mobile") == null || StringUtils.isEmpty(p.get("mobile").toString())||Integer.parseInt(p.get("status").toString())!=1) {
                    continue;
                }
                String msg = "尊敬的" + p.get("name").toString() + "，" + doctor.getName() + "医生提醒您：" +
                        "为更好地为您提供健康服务，请您关注并登录\"厦门i健康\"微信公众号，与医生进行互动。";
                JSONObject smsResult = SMSService.sendMsg(p.get("mobile").toString(), msg);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
