package cn.com.ty.lift.ud.userAgreement.service.impl;

import java.util.List;

import cn.com.ty.lift.ud.userAgreement.controller.query.UserAgreementQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cn.com.ty.lift.ud.userAgreement.mapper.UserAgreementMapper;
import cn.com.ty.lift.ud.userAgreement.mapper.entity.UserAgreement;
import cn.com.ty.lift.ud.userAgreement.service.IUserAgreementService;
import cn.com.xwy.boot.web.dto.RestResponse;

/**
 * 用户协议 -ServiceImpl
 *
 * @author Xson
 * @date 2020-05-13
 */
@Service
@Transactional
public class UserAgreementServiceImpl extends ServiceImpl<UserAgreementMapper, UserAgreement>
    implements IUserAgreementService {

    @Autowired
    private UserAgreementMapper userAgreementMapper;

    @Override
    public void updateByIds(List<Long> ids, Integer status) {
        for (Long id : ids) {
            UserAgreement bit = new UserAgreement();
            bit.setId(id);
            bit.setStatuz(status);
            userAgreementMapper.updateById(bit);
        }
    }

    @Override
    public RestResponse selectByExample(UserAgreementQuery query) {
        IPage page = query.page();
        List<UserAgreement> list = userAgreementMapper.selectByQuery(query.condition(), query);
        int total = userAgreementMapper.countByQuery(query.condition());
        page.setRecords(list);
        page.setTotal(total);
        return RestResponse.success(page, "Queried successfully");
    }

    @Override
    public RestResponse queryListCharge() {
        List<UserAgreement> queryListCharge = userAgreementMapper.queryListCharge();
        return RestResponse.success(queryListCharge, "请求成功");
    }

}
