package xiaoqu.home.open.service.db2.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import xiaoqu.home.open.mapper.db2.UserPushMapper;
import xiaoqu.home.open.model.db1.User;
import xiaoqu.home.open.model.db2.UserPush;
import xiaoqu.home.open.service.db2.UserPushService;

/**
 * <p>
 * 用户个推 服务实现类
 * </p>
 *
 * @author mk
 * @since 2022-05-19
 */
@Service
public class UserPushServiceImpl extends ServiceImpl<UserPushMapper, UserPush> implements UserPushService {

    public void checkIsCreate(User user, String clientId) {
        QueryWrapper<UserPush> wrapper = new QueryWrapper<UserPush>();
        wrapper.eq("user_id", user.getId());
        wrapper.eq("soft_delete", 0);
        List<UserPush> userPushList = this.list(wrapper);
        UserPush userPush = null;
        if (userPushList.isEmpty()) {
            userPush = new UserPush();
            userPush.setAgentId(user.getAgentId());
            userPush.setClientId(clientId);
            userPush.setPropertyId(user.getPropertyId());
            userPush.setUserId(user.getId());
            userPush.setStatus(0);
            this.save(userPush);
        } else {
            userPush = userPushList.get(0);
            userPush.setClientId(clientId);
            this.updateById(userPush);
        }

    }
}
