package com.eleadmin.oa.server.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.eleadmin.common.core.utils.CommonUtil;
import com.eleadmin.common.core.web.PageParam;
import com.eleadmin.common.core.web.PageResult;
import com.eleadmin.oa.entity.AssetsData;
import com.eleadmin.oa.mapper.AssetsDataMapper;
import com.eleadmin.oa.param.AssetsDataParam;
import com.eleadmin.oa.server.AssetsDataService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 资产数据Service实现
 *
 * @author gxwebsoft.com
 * @since 2020-03-14 11:29:04
 */
@Service
public class AssetsDataServiceImpl extends ServiceImpl<AssetsDataMapper, AssetsData>
        implements AssetsDataService {

    @Override
    public PageResult<AssetsData> pageRel(AssetsDataParam param) {
        PageParam<AssetsData, AssetsDataParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number");
        return new PageResult<>(baseMapper.selectPageRel(page, param), page.getTotal());
    }

    @Override
    public List<AssetsData> listRel(AssetsDataParam param) {
        PageParam<AssetsData, AssetsDataParam> page = new PageParam<>(param);
        page.setDefaultOrder("sort_number");
        return page.sortRecords(baseMapper.selectListRel(param));
    }

    @Override
    public AssetsData getByIdRel(Integer assetsDataId) {
        AssetsDataParam param = new AssetsDataParam();
        param.setAssetsDataId(assetsDataId);
        return param.getOne(baseMapper.selectListRel(param));
    }

    @Override
    public AssetsData getByAssetsCodeAndName(String assetsCode, String assetsDataName) {
        List<AssetsData> list = baseMapper.getByAssetsCodeAndName(assetsCode, assetsDataName);
        return CommonUtil.listGetOne(list);
    }

}
