package com.hfkj.service.user.impl;

import com.hfkj.dao.BsUserMsgSubMapper;
import com.hfkj.entity.BsUserMsgSub;
import com.hfkj.entity.BsUserMsgSubExample;
import com.hfkj.service.user.BsUserMsgSubService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @className: BsUserMsgSubServiceImpl
 * @author: HuRui
 * @date: 2025/3/18
 **/
@Service("userMsgSubService")
public class BsUserMsgSubServiceImpl implements BsUserMsgSubService {
    @Resource
    private BsUserMsgSubMapper userMsgSubMapper;

    @Override
    public void editData(BsUserMsgSub data) {
        data.setUpdateTime(new Date());
        if (data.getId() == null) {
            data.setCreateTime(new Date());
            userMsgSubMapper.insert(data);
        } else {
            userMsgSubMapper.updateByPrimaryKey(data);
        }
    }

    @Override
    public BsUserMsgSub getDetail(Long userId, String subscribeId) {
        BsUserMsgSubExample example = new BsUserMsgSubExample();
        example.createCriteria()
                .andUserIdEqualTo(userId)
                .andSubscribeIdEqualTo(subscribeId)
                .andStatusNotEqualTo(0);
        List<BsUserMsgSub> list = userMsgSubMapper.selectByExample(example);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }
}
