MAccountServiceImpl.java 1.84 KB
package vion.service.impl.monitor;

import com.github.yulichang.base.MPJBaseServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import vion.mapper.monitor.MAccountMapper;
import vion.model.monitor.MAccount;
import vion.model.monitor.RAccountEvent;
import vion.model.monitor.RUserAccount;
import vion.service.monitor.IMAccountService;
import vion.service.monitor.IRAccountEventService;
import vion.service.monitor.IRUserAccountService;

import java.util.List;

/**
 * @author vion
 * @date 2024/10/31
 */
@Service
@RequiredArgsConstructor
public class MAccountServiceImpl extends MPJBaseServiceImpl<MAccountMapper, MAccount> implements IMAccountService {

    private final IRAccountEventService accountEventService;
    private final IRUserAccountService userAccountService;

    @Override
    public List<RAccountEvent> getEventById(String uid) {
        return accountEventService.lambdaQuery().eq(RAccountEvent::getAccountUid, uid).list();
    }

    @Override
    public String saveEvent(String agentUid, String uid, RAccountEvent event) {
        event.setAgentUid(agentUid);
        event.setAccountUid(uid);
        return accountEventService.save(event) ? "成功" : "失败";
    }

    @Override
    public List<RUserAccount> subList(Long userId) {
        return userAccountService.lambdaQuery().eq(RUserAccount::getUserId, userId).list();
    }

    @Override
    public String sub(RUserAccount userAccount) {
        return userAccountService.save(userAccount) ? "订阅成功" : "订阅失败";
    }

    @Override
    public String unsub(RUserAccount userAccount) {
        return userAccountService.lambdaUpdate()
                .eq(RUserAccount::getAccountId, userAccount.getAccountId())
                .eq(RUserAccount::getUserId, userAccount.getUserId()).remove() ? "取消订阅成功" : "取消订阅失败";
    }
}