package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerContractSettleRuleMapper;
import com.gxwebsoft.tower.service.TowerContractSettleRuleService;
import com.gxwebsoft.tower.entity.TowerContractSettleRule;
import com.gxwebsoft.tower.param.TowerContractSettleRuleParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 合同结算规则Service实现
 *
 * @author 科技小王子
 * @since 2023-06-11 13:48:41
 */
@Service
public class TowerContractSettleRuleServiceImpl extends ServiceImpl<TowerContractSettleRuleMapper, TowerContractSettleRule> implements TowerContractSettleRuleService {

    @Override
    public PageResult<TowerContractSettleRule> pageRel(TowerContractSettleRuleParam param) {
        PageParam<TowerContractSettleRule, TowerContractSettleRuleParam> page = new PageParam<>(param);
        //page.setDefaultOrder("create_time desc");
        List<TowerContractSettleRule> list = baseMapper.selectPageRel(page, param);
        return new PageResult<>(list, page.getTotal());
    }

    @Override
    public List<TowerContractSettleRule> listRel(TowerContractSettleRuleParam param) {
        List<TowerContractSettleRule> list = baseMapper.selectListRel(param);
        // 排序
        PageParam<TowerContractSettleRule, TowerContractSettleRuleParam> page = new PageParam<>();
        //page.setDefaultOrder("create_time desc");
        return page.sortRecords(list);
    }

    @Override
    public TowerContractSettleRule getByIdRel(Integer contractSettleRuleId) {
        TowerContractSettleRuleParam param = new TowerContractSettleRuleParam();
        param.setContractSettleRuleId(contractSettleRuleId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
