package com.yh.saas.plugin.yiliangyiyun.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.google.common.collect.Lists;
import com.winsea.svc.base.security.util.AuthSecurityUtils;
import com.yh.saas.plugin.yiliangyiyun.entity.ContractExpensesInfo;
import com.yh.saas.plugin.yiliangyiyun.mapper.ContractExpensesInfoMapper;
import com.yh.saas.plugin.yiliangyiyun.service.IContractExpensesInfoService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

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

/**
 * <p>
 * 合同费用 服务实现类
 * </p>
 *
 * @author Gdc
 * @since 2022-05-24
 */
@Service
public class ContractExpensesInfoServiceImpl extends ServiceImpl<ContractExpensesInfoMapper, ContractExpensesInfo> implements IContractExpensesInfoService {

    /**
     * 合同/库点费用列表查询
     * @param contractExpensesInfo
     * @return
     */
    @Override
    public Page<ContractExpensesInfo> selectContractExpensesInfo(ContractExpensesInfo contractExpensesInfo) {
        Map<String, Object> pageView = new HashMap<>();
        pageView.put("startRecord", (contractExpensesInfo.getCurrentPage() - 1)
                * contractExpensesInfo.getPageSize());
        //  公司ID
        pageView.put("compId", AuthSecurityUtils.getCurrentUserInfo().getCompId());
        pageView.put("contractNo", contractExpensesInfo.getContractNo());
        pageView.put("costType",contractExpensesInfo.getCostType());
        pageView.put("warehouseName",contractExpensesInfo.getWarehouseName());
        pageView.put("startDate", contractExpensesInfo.getStartDate());
        pageView.put("endDate", contractExpensesInfo.getEndDate());
        pageView.put("pageSize", contractExpensesInfo.getPageSize());
        pageView.put("currentPage", contractExpensesInfo.getCurrentPage());
        // 查询服务商总数
        Integer dataCount = baseMapper.getContractExpensesCountByCondition(pageView);
        List<ContractExpensesInfo> dataList = baseMapper.getContractExpensesListByCondition(pageView);

        Page<ContractExpensesInfo> page = new Page<>();
        page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
        page.setTotal(dataCount == null ? 0 : dataCount);
        page.setCurrent(contractExpensesInfo.getCurrentPage());
        page.setSize(contractExpensesInfo.getPageSize());
        return page;
    }
}
