package com.ktg.iscs.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ktg.common.utils.StringUtils;
import com.ktg.iscs.domain.IsUnit;
import com.ktg.iscs.mapper.IsUnitMapper;
import com.ktg.iscs.service.IIsUnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 单位管理Service业务层处理
 *
 * @author cgj
 * @date 2024-12-18
 */
@Service
public class IsUnitServiceImpl extends ServiceImpl<IsUnitMapper, IsUnit> implements IIsUnitService {

    @Autowired
    private IsUnitMapper isUnitMapper;

    @Override
    public Page<IsUnit> getIsUnitPage(Page<IsUnit> page, IsUnit isUnit) {
        Page<IsUnit> result = page(page, Wrappers.<IsUnit>lambdaQuery()
                .eq(isUnit.getUnitId() != null, IsUnit::getUnitId, isUnit.getUnitId())
                .like(StringUtils.isNotBlank(isUnit.getUnitName()), IsUnit::getUnitName, isUnit.getUnitName())
                .eq(StringUtils.isNotBlank(isUnit.getStatus()), IsUnit::getStatus, isUnit.getStatus())
                .orderByAsc(IsUnit::getOrderNum)
                .orderByDesc(IsUnit::getUnitId));
        return result;
    }
}
