package com.ruoyi.web.modules.entry.support;

import java.util.Date;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.ruoyi.web.modules.entry.constant.MerchantEntryApplyConstants;
import com.ruoyi.web.modules.entry.domain.BizMemberMessage;
import com.ruoyi.web.modules.entry.mapper.BizMemberMessageMapper;

/**
 * 入驻审核结果站内消息
 */
@Component
public class MemberEntryMessageSupport
{
    @Autowired
    private BizMemberMessageMapper messageMapper;

    public void sendPublicity(Long memberId, Long applyId, String applyNo, Date publicityEndTime)
    {
        BizMemberMessage message = new BizMemberMessage();
        message.setMemberId(memberId);
        message.setBizType(MerchantEntryApplyConstants.BIZ_TYPE_ENTRY_AUDIT);
        message.setBizId(applyId);
        message.setTitle(MerchantEntryApplyConstants.MSG_PUBLICITY_TITLE);
        message.setContent("您的入驻申请（" + applyNo + "）已审核通过，进入公示期，公示结束后将自动完成入驻。"
                + (publicityEndTime != null ? "预计完成时间：" + new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm").format(publicityEndTime) : ""));
        message.setReadFlag("0");
        messageMapper.insert(message);
    }

    public void sendPass(Long memberId, Long applyId, String applyNo)
    {
        BizMemberMessage message = new BizMemberMessage();
        message.setMemberId(memberId);
        message.setBizType(MerchantEntryApplyConstants.BIZ_TYPE_ENTRY_AUDIT);
        message.setBizId(applyId);
        message.setTitle(MerchantEntryApplyConstants.MSG_PASS_TITLE);
        message.setContent("您的入驻申请（" + applyNo + "）已完成公示，入驻成功，可使用经营账号登录商家端。");
        message.setReadFlag("0");
        messageMapper.insert(message);
    }

    public void sendReject(Long memberId, Long applyId, String applyNo, String rejectReason)
    {
        BizMemberMessage message = new BizMemberMessage();
        message.setMemberId(memberId);
        message.setBizType(MerchantEntryApplyConstants.BIZ_TYPE_ENTRY_AUDIT);
        message.setBizId(applyId);
        message.setTitle(MerchantEntryApplyConstants.MSG_REJECT_TITLE);
        message.setContent("您的入驻申请（" + applyNo + "）未通过审核。原因：" + rejectReason);
        message.setReadFlag("0");
        messageMapper.insert(message);
    }
}
