package com.diagbot.facade;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.diagbot.dto.VersionDetailDTO;
import com.diagbot.entity.VersionDetail;
import com.diagbot.enums.IsDeleteEnum;
import com.diagbot.enums.StatusEnum;
import com.diagbot.service.impl.VersionDetailServiceImpl;
import com.diagbot.util.BeanUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author wangfeng
 * @Description:
 * @date 2024-07-27 14:45
 */
@Component
public class VersionDetailFacade extends VersionDetailServiceImpl {

    /**
     * 根据版本id查询版本详情
     *
     * @param id
     * @return
     */
    public List<VersionDetailDTO> getById(Long id) {
        QueryWrapper<VersionDetail> versionDetailQuery = new QueryWrapper<>();
        Map<String, Object> mapAll = new HashMap<>();
        mapAll.put("is_deleted", IsDeleteEnum.N.getKey());
        mapAll.put("version_id", id);
        mapAll.put("STATUS", StatusEnum.Enable.getKey());
        versionDetailQuery.allEq(mapAll).orderByDesc("gmt_create").orderByAsc("order_no");

        VersionDetail versionDetail = new VersionDetail();
        versionDetail.setVersionId(id);
        List<VersionDetail> datas = list(versionDetailQuery);
        List<VersionDetailDTO> dataNew = new ArrayList<VersionDetailDTO>();
        //过滤字段
        dataNew = BeanUtil.listCopyTo(datas, VersionDetailDTO.class);
        return dataNew;

    }
}
