package com.flossom.miniProgram.service.impl;

import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.entity.WxNoRemindRecord;
import com.flossom.common.core.mapper.WxNoRemindRecordMapper;
import com.flossom.common.core.utils.DateUtils;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.security.utils.SecurityUtils;
import com.flossom.miniProgram.service.IWxNoRemindService;
import com.flossom.miniProgram.utils.MiniProgramUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class WxNoRemindServiceImpl implements IWxNoRemindService {

    @Autowired
    private WxNoRemindRecordMapper wxNoRemindRecordMapper;

    @Override
    public Integer officialAccount() {
        return wxNoRemindRecordMapper.selectWxNoRemindRecordByOpenid(SecurityUtils.getLoginUser().getWxUserMember().getOpenid());
    }

    @Override
    public void closeOfficialAccount() {
        WxNoRemindRecord wxNoRemindRecord = new WxNoRemindRecord();
        wxNoRemindRecord.setOpenid(SecurityUtils.getLoginUser().getWxUserMember().getOpenid());
        wxNoRemindRecord.setCreateTime(DateUtils.getNowDate());
        wxNoRemindRecordMapper.insertWxNoRemindRecord(wxNoRemindRecord);
    }

    @Override
    public Boolean isAttentionOfficialAccount() throws Exception {
        return MiniProgramUtils.isAttentionOfficialAccount(SecurityUtils.getLoginUser().getWxUserMember().getUnionid());
    }
}
