package com.backendsys.modules.system.service.impl;

import com.backendsys.exception.CustException;
import com.backendsys.modules.system.dao.SysAgreementDao;
import com.backendsys.modules.system.entity.SysAgreement;
import com.backendsys.modules.system.service.SysAgreementService;
import com.backendsys.utils.response.PageEntity;
import com.backendsys.utils.response.PageInfoResult;
import com.backendsys.utils.v2.PageUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysAgreementServiceImpl implements SysAgreementService {

    @Autowired
    private SysAgreementDao sysAgreementDao;

    /**
     * 获得协议列表
     */
    @Override
    public PageEntity selectAgreementList(SysAgreement sysAgreement) {
        PageUtils.startPage();  // 分页
        List<SysAgreement> list = sysAgreementDao.selectList(new QueryWrapper<>());
        return new PageInfoResult(list).toEntity();
    }

    /**
     * 获得协议详情 (By tag)
     */
    @Override
    public SysAgreement selectAgreementByTag(String tag) {
        SysAgreement detail = sysAgreementDao.selectOne(new LambdaQueryWrapper<SysAgreement>().eq(SysAgreement::getTag, tag));
        if (detail == null) throw new CustException("协议不存在");
        return detail;
    }

}
