/**
 * bobotuan.com Inc. Copyright (c) 2004-2020 All Rights Reserved.
 */
package com.qs.mp.framework.domain;

import com.qs.mp.common.utils.DateUtils;
import java.text.DecimalFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import lombok.Data;
import org.apache.commons.lang3.time.DateFormatUtils;

/**
 * 微信公众号模板消息（具体参见https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html）
 *
 *
 *
 * @author zhongcp
 */
@Data
public class WxTemplateMessage {

  private String touser;
  private String template_id;
  private MiniProgram miniprogram = new MiniProgram();
  private Map<String, TemplateData> data = new HashMap<>();


  /**
   * 通知消息
   *
   * @param openid 用户id
   */
  public WxTemplateMessage(String appId, String openid) {
    miniprogram.setAppid(appId);
    touser = openid;
  }
/*
  public void buildBillPaySuccessMessage(MerchantBill merchantBill, Merchant merchant) {
    template_id = "DuWP0BvER8yBe06Vjdr5d8XOuv1LPwLJORNvlg4LkaQ";
    miniprogram.setPagepath("/pages/bills/detail?id=" + merchantBill.getBillId() + "&custId="
        + merchantBill.getCustId());
    *//**
     * {{first.DATA}}
     * 缴费项目：{{keyword1.DATA}}
     * 缴费金额：{{keyword2.DATA}}
     * 缴费时间：{{keyword3.DATA}}
     * {{remark.DATA}}
     *//*
    data.put("first", new com.qs.ygp.framework.domain.TemplateData("尊敬的" + merchant.getBrand() + "商户，您有一笔账单支付成功了！", "#173177"));
    data.put("keyword1", new com.qs.ygp.framework.domain.TemplateData(merchantBill.getBillType().getDesc(), "#173177"));
    DecimalFormat df = new DecimalFormat("0.00");//格式化小数
    data.put("keyword2",
        new com.qs.ygp.framework.domain.TemplateData(df.format((float)merchantBill.getPayedAmt() / 100) + "元", "#173177"));
    data.put("keyword3", new com.qs.ygp.framework.domain.TemplateData(
        DateFormatUtils.format(null == merchantBill.getPayTime() ? new Date() : merchantBill.getPayTime(), DateUtils.YYYY_MM_DD_HH_MM_SS),
        "#173177"));
    data.put("remark", new com.qs.ygp.framework.domain.TemplateData("点击查看账单详情", "#173177"));
  }

  public void buildBillPayFailMessage(MerchantBill merchantBill, Merchant merchant, int offDays) {
    template_id = "c4xSJfhwfq8C6wDgsPOrjPSiW0_fCk2xVrYAcp6-xeA";
    miniprogram.setPagepath("/pages/bills/detail?id=" + merchantBill.getBillId() + "&custId="
        + merchantBill.getCustId());
    *//**
     *  {{first.DATA}}
     * 缴费时间：{{keyword1.DATA}}
     * 缴费方式：{{keyword2.DATA}}
     * 缴费金额：{{keyword3.DATA}}
     * 失败原因：{{keyword4.DATA}}
     * {{remark.DATA}}
     *//*
    data.put("first", new com.qs.ygp.framework.domain.TemplateData("尊敬的" + merchant.getBrand() + "商户，您有一笔账单支付失败了！", "#173177"));
    data.put("keyword1",
        new com.qs.ygp.framework.domain.TemplateData(DateFormatUtils.format(new Date(), DateUtils.YYYY_MM_DD_HH_MM_SS),
            "#173177"));
    data.put("keyword2", new com.qs.ygp.framework.domain.TemplateData("充值余额支付", "#173177"));
    DecimalFormat df = new DecimalFormat("0.00");//格式化小数
    data.put("keyword3",
        new com.qs.ygp.framework.domain.TemplateData(df.format((float)(merchantBill.getBillAmt() - merchantBill.getRealAmt()) / 100) + "元", "#173177"));
    data.put("keyword4", new com.qs.ygp.framework.domain.TemplateData("余额不足", "#173177"));
    StringBuilder sb = new StringBuilder();
    if (offDays > 0) {
      sb.append("系统将在").append(offDays).append("天后自动断电，");
    }
    sb.append("请及时充值或线下转账到公司指定账户，以免系统自动断电，造成不必要的损失！");
    data.put("remark", new com.qs.ygp.framework.domain.TemplateData(sb.toString(), "#173177"));

  }

  public void buildBillPayConfirmMessage(MerchantBill merchantBill, MerchantBillPayLog payLog,
      Merchant merchant) {
    template_id = "TW_h1DI4mDPZFeB9qaocrV07ovakYs_Y6cXiQLNCxlY";
    miniprogram.setPagepath("/pages/bills/detail?id=" + merchantBill.getBillId() + "&custId="
        + merchantBill.getCustId());

    *//**
     *  {{first.DATA}}
     * 应付金额：{{keyword1.DATA}}
     * 实付金额：{{keyword2.DATA}}
     * 备注说明：{{keyword3.DATA}}
     * {{remark.DATA}}
     *//*
    data.put("first", new com.qs.ygp.framework.domain.TemplateData("尊敬的" + merchant.getBrand() + "商户，您有一笔账单付款被" +
        (payLog.getStatus() == PayStatusEnum.SUCCESS ? "确认" : "驳回") + "了！", "#173177"));
    DecimalFormat df = new DecimalFormat("0.00");//格式化小数
    data.put("keyword1",
        new com.qs.ygp.framework.domain.TemplateData(df.format((float) payLog.getPayAmt() / 100) + "元", "#173177"));
    data.put("keyword2",
        new com.qs.ygp.framework.domain.TemplateData(df.format((float)payLog.getConfirmAmt() / 100) + "元", "#173177"));
    data.put("keyword3", new com.qs.ygp.framework.domain.TemplateData(
        merchantBill.getStatus() == BillStatusEnum.FINISHED ? "整笔账单已结清！"
            : "整笔账单还剩余" + df.format((float)(merchantBill.getBillAmt() - merchantBill.getRealAmt()) / 100)
                + "元未结清，请及时充值或线下转账到公司指定账户，以免系统自动断电，造成不必要的损失！", "#173177"));
    data.put("remark", new com.qs.ygp.framework.domain.TemplateData("点击查看账单详情", "#173177"));
  }

  public void buildDepositRemindMessage(Merchant merchant) {
    template_id = "2XZVkvPh5yqFGGHk6XmFw2rlarrMRawSNLfA_O1TqXQ";
    miniprogram.setPagepath("/pages/deposit/index?merchId=" + merchant.getMerchId() + "&custId="
        + merchant.getCustId());
    *//**
     *  {{first.DATA}}
     * 账户余额：{{keyword1.DATA}}
     * 时间：{{keyword2.DATA}}
     * {{remark.DATA}}
     *//*
    data.put("first",
        new com.qs.ygp.framework.domain.TemplateData("尊敬的" + merchant.getBrand() + "商户，您的充值账户余额不足500了！", "#173177"));
    DecimalFormat df = new DecimalFormat("0.00");//格式化小数
    data.put("keyword1",
        new com.qs.ygp.framework.domain.TemplateData(df.format((float) merchant.getMoney() / 100) + "元", "#173177"));
    data.put("keyword2",
        new com.qs.ygp.framework.domain.TemplateData(DateFormatUtils.format(new Date(), DateUtils.YYYY_MM_DD_HH_MM_SS),
            "#173177"));
    data.put("remark", new com.qs.ygp.framework.domain.TemplateData("请及时充值，以免系统自动断电，造成不必要的损失。点击去充值！", "#173177"));
  }

  public void buildCustomerRechargeRemindMessage(Customer customer, Date remindDay) {
    template_id = "xsZyCAk-bMuWB7NycHUACBmte87NCjveA_aW8P9NZGI";
    miniprogram.setPagepath("/pages/renew/index");
    *//**
     *  {{first.DATA}}
     * 服务主题：{{keyword1.DATA}}
     * 服务内容：{{keyword2.DATA}}
     * 到期时间：{{keyword3.DATA}}
     * {{remark.DATA}}
     *//*
    String msg = "您的服务即将到期！";
    int diffDays = DateUtils.diff(remindDay, customer.getDueDate());
    if (diffDays >= 0 && diffDays < 7) {
      msg = "您的服务将于" + diffDays + "天后到期！";
    } else if (diffDays < 0) {
      msg = "您的服务已到期！";
    }
    data.put("first",
        new com.qs.ygp.framework.domain.TemplateData("尊敬的" + customer.getBrand() + "客户，" + msg, "#173177"));
    DecimalFormat df = new DecimalFormat("0.00");//格式化小数
    data.put("keyword1",
        new com.qs.ygp.framework.domain.TemplateData(customer.getPackageType().getDesc(), "#173177"));
    data.put("keyword2",
        new com.qs.ygp.framework.domain.TemplateData("账单自动生成、多渠道提醒、智能催缴", "#173177"));
    data.put("keyword3",
        new com.qs.ygp.framework.domain.TemplateData(DateFormatUtils.format(customer.getDueDate(), DateUtils.YYYY_MM_DD),
            "#173177"));
    data.put("remark", new com.qs.ygp.framework.domain.TemplateData("请及时续费，以免系统自动停止生成账单，造成不必要的损失。点击去续费！", "#173177"));
  }*/


}
