package com.zt.plat.module.qms.common.service;

import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.module.infra.api.businessfile.BusinessFileApi;
import com.zt.plat.module.infra.api.businessfile.dto.BusinessFilePageReqDTO;
import com.zt.plat.module.infra.api.businessfile.dto.BusinessFileRespDTO;
import com.zt.plat.module.infra.api.businessfile.dto.BusinessFileWithUrlRespDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;

@Service("businessFileService")
public class BusinessFileService {

    @Resource BusinessFileApi businessFileApi;

    /*
    * 调用平台的业务附件接口删除附件记录
    * */
    public void deleteBusinessFileList(List<Long> idsList){
        if(idsList == null || idsList.isEmpty())
            return;
        businessFileApi.deleteBusinessFileList(idsList);
    }

    /*
    * 查询附件列表
    * */
    public CommonResult<List<BusinessFileWithUrlRespDTO>> getBusinessFileList(Long businessId){
        BusinessFilePageReqDTO businessFilePageReqDTO = new BusinessFilePageReqDTO();
        businessFilePageReqDTO.setBusinessId(businessId);
        businessFilePageReqDTO.setPageSize(-1);
        CommonResult<PageResult<BusinessFileWithUrlRespDTO>> ret = businessFileApi.getBusinessFilePageWithUrl(businessFilePageReqDTO);
        if(!ret.isSuccess())
            return CommonResult.error(ret);
        PageResult<BusinessFileWithUrlRespDTO> pageResult = ret.getData();
        List<BusinessFileWithUrlRespDTO> list = pageResult.getList();
        return CommonResult.success(list);
    }

}
