package com.ema.admin.modules.assets.service.impl;

import cn.hutool.core.util.StrUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.ema.admin.modules.assets.entity.AssetStatusHistory;
import com.ema.admin.modules.assets.mapper.AssetStatusHistoryMapper;
import com.ema.admin.modules.assets.service.AssetStatusHistoryService;
import com.ema.admin.modules.assets.vo.AssetStatusHistoryQueryVo;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 *  资产状态历史表服务层实现。
 *
 * @author LIJIAN
 * @since 2026-05-13
 */
@Service
public class AssetStatusHistoryServiceImpl extends ServiceImpl<AssetStatusHistoryMapper, AssetStatusHistory> implements AssetStatusHistoryService {

    @Override
    public List<AssetStatusHistory> listByAssetId(String assetId) {
        QueryWrapper queryWrapper = QueryWrapper.create()
                .eq(AssetStatusHistory::getAssetId, assetId)
                .orderBy(AssetStatusHistory::getOperatorDate, false);
        return list(queryWrapper);
    }

    @Override
    public Page<AssetStatusHistory> page(AssetStatusHistoryQueryVo queryVo) {
        QueryWrapper queryWrapper = QueryWrapper.create();
        queryWrapper.eq(AssetStatusHistory::getAssetId, queryVo.getAssetId(), StrUtil.isNotBlank(queryVo.getAssetId()));
        queryWrapper.eq(AssetStatusHistory::getUseStatus, queryVo.getUseStatus(), StrUtil.isNotBlank(queryVo.getUseStatus()));
        queryWrapper.like(AssetStatusHistory::getUseDept, queryVo.getUseDept(), StrUtil.isNotBlank(queryVo.getUseDept()));
        queryWrapper.like(AssetStatusHistory::getUseUser, queryVo.getUseUser(), StrUtil.isNotBlank(queryVo.getUseUser()));
        queryWrapper.orderBy(AssetStatusHistory::getOperatorDate, false);
        return this.page(new Page<>(queryVo.getPageNumber(), queryVo.getPageSize()), queryWrapper);
    }
}
