package io.renren.modules.business.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.business.dao.BusinessContractDao;
import io.renren.modules.business.entity.BusinessContractEntity;
import io.renren.modules.business.service.BusinessContractService;
import org.springframework.stereotype.Service;

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


@Service("businessContractService")
public class BusinessContractServiceImpl extends ServiceImpl<BusinessContractDao, BusinessContractEntity> implements BusinessContractService {

    /**
     * 暂废
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
       /*QueryWrapper<BusinessContractEntity> qw = new QueryWrapper<>();
        //建设单位 需要表关联  待做
        if (params.get("contractJsdwId") != null && !params.get("contractJsdwId").equals("") && !params.get("contractJsdwId").equals("undefined")) {
            *//*String strSql = null;
            if(params.get("contractJsdwId").toString().contains(",")){
                String[] str = params.get("contractJsdwId").toString().split(",");
                for(int i = 0;i < str.length;i++){
                    if(strSql == null){
                        strSql = " and concat(',',contract_jsdw_id,',') like '%,"+ str[i] +",%' ";
                    } else {
                        strSql += " and concat(',',contract_jsdw_id,',') like '%,"+ str[i] +",%' ";
                    }
                }
            }else{
                strSql = " and concat(',',project_gclb_id,',') like '%,"+ params.get("contractJsdwId").toString() +",%' ";
            }
            qw.last(strSql);*//*
        }
        //年份
        if (params.get("contractYear") != null && !params.get("contractYear").equals("") && !params.get("contractYear").equals("undefined")) {
            qw.eq("contract_year", params.get("contractYear"));
        }
        //监理单位
        if (params.get("contractJldwId") != null && !params.get("contractJldwId").equals("") && !params.get("contractJldwId").equals("undefined")) {
            qw.eq("contract_jldw_id", params.get("contractJldwId"));
        }
        //施工单位
        if (params.get("contractSgdwId") != null && !params.get("contractSgdwId").equals("") && !params.get("contractSgdwId").equals("undefined")) {
            qw.eq("contract_sgdw_id", params.get("contractSgdwId"));
        }
        IPage<BusinessContractEntity> page = this.page(
                new Query<BusinessContractEntity>().getPage(params),
                qw
        );*/

        IPage<BusinessContractEntity> page = new Query<BusinessContractEntity>().getPage(params);
        List<BusinessContractEntity> list = baseMapper.queryList(params);
        page.setRecords(list);
        return new PageUtils(page);
    }

    @Override
    public PageUtils queryList(Map<String, Object> params) {
        IPage<BusinessContractEntity> page = new Query<BusinessContractEntity>().getPage(params);
        List<BusinessContractEntity> list = baseMapper.queryList(params);
        page.setRecords(list);
        return new PageUtils(page);
    }

    //根据projectId获取立项信息
    @Override
    public Map<String, Object> getByProjectId(String projectId) {
        String[] ids = projectId.split(",");
        Map<String,Object> map = new HashMap<>();
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        for(String id:ids){
            map.put(id,baseMapper.getByProjectId(id));
        }
        list.add(map);
        return map;
    }

}