package com.gxwebsoft.tower.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.tower.mapper.TowerSecurityRecordMapper;
import com.gxwebsoft.tower.service.TowerSecurityRecordService;
import com.gxwebsoft.tower.entity.TowerSecurityRecord;
import com.gxwebsoft.tower.param.TowerSecurityRecordParam;
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 2024-02-22 13:44:23
 */
@Service
public class TowerSecurityRecordServiceImpl extends ServiceImpl<TowerSecurityRecordMapper, TowerSecurityRecord> implements TowerSecurityRecordService {

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

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

    @Override
    public TowerSecurityRecord getByIdRel(Integer securityId) {
        TowerSecurityRecordParam param = new TowerSecurityRecordParam();
        param.setSecurityId(securityId);
        return param.getOne(baseMapper.selectListRel(param));
    }

}
