package com.dsk.cscec.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.map.MapUtil;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsk.common.core.domain.PageQuery;
import com.dsk.common.core.page.TableDataInfo;
import com.dsk.cscec.domain.DContract;
import com.dsk.cscec.domain.bo.ProjectSearchBo;
import com.dsk.cscec.domain.vo.ProjectSearchVo;
import com.dsk.cscec.mapper.AdvisoryBodyCustomFormDataMapper;
import com.dsk.cscec.mapper.DContractMapper;
import com.dsk.cscec.service.DContractService;
import com.dsk.search.service.BusinessOpportunityRadarService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 合同维表(DContract)表服务实现类
 *
 * @author sxk
 * @since 2024-06-21 13:38:29
 */
@Service("dContractService")
public class DContractServiceImpl extends ServiceImpl<DContractMapper, DContract> implements DContractService {
    @Resource
    private DContractMapper baseMapper;
    @Resource
    private AdvisoryBodyCustomFormDataMapper formDataMapper;
    @Resource
    private BusinessOpportunityRadarService opportunityRadarService;

    /**
     * 获取所有项目列表数据
     *
     * @param projectSearchBo 查询实体
     * @param pageQuery       分页对象
     * @return 所有数据
     */
    @Override
    public TableDataInfo<ProjectSearchVo> queryProjectList(ProjectSearchBo projectSearchBo, PageQuery pageQuery) {
        Page<ProjectSearchVo> page = baseMapper.selectPageProjectList(pageQuery.build(), projectSearchBo);
        page.getRecords().stream().forEach(dto ->{
            Map<String, Object> map = opportunityRadarService.enterpriseByName(dto.getOwnerName());
            if (!ObjectUtils.isEmpty(map.get("data"))) {
                Map<String, Object> data = BeanUtil.beanToMap(map.get("data"));
                Integer companyId = MapUtil.getInt(data, "jskEid");
                dto.setOwnerUnitCid(companyId);
            }
        });


        return TableDataInfo.build(page);
    }
}

