package org.jeecg.modules.finance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.basedata.entity.FdPersonnel;
import org.jeecg.modules.basedata.mapper.FdPersonnelMapper;
import org.jeecg.modules.basedata.service.IFdPersonnelService;
import org.jeecg.modules.finance.entity.FdFinancialStatements;
import org.jeecg.modules.finance.mapper.FdFinancialStatementsMapper;
import org.jeecg.modules.finance.service.IFdFinancialStatementsService;
import org.jeecg.modules.projectManagement.entity.FdProjectFileCompound;
import org.jeecg.modules.projectManagement.service.IFdProjectFileCompoundService;
import org.jeecg.modules.sampleAndConsumableManagement.controller.FdColumnManagementController;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

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

/**
 * @Description: 财务报表
 * @author： jeecg-boot
 * @date：   2019-07-24
 * @version： V1.0
 */
@Service
public class FdFinancialStatementsServiceImpl extends ServiceImpl<FdFinancialStatementsMapper, FdFinancialStatements> implements IFdFinancialStatementsService {

    @Resource
    FdFinancialStatementsMapper fdFinancialStatementsMapper;

    @Resource
    FdColumnManagementController fdColumnManagementController;

    @Resource
    IFdPersonnelService fdPersonnelService;

    @Resource
    private IFdProjectFileCompoundService fdProjectFileCompoundService;

    /**
     * @Author gurui
     * @Description //TODO 根据合同号查询报表名称为本月到款情况
     * @Date 15:45 2019/7/25
     * @Param [contractId]
     * @return org.jeecg.modules.finance.entity.FdFinancialStatements
     **/
    @Override
    public List<FdFinancialStatements> queryByConId1(FdFinancialStatements financialStatements) {
        List<FdFinancialStatements> list = fdFinancialStatementsMapper.queryByConId1(financialStatements);
        // String compound = "";
        // Integer i = 0;
        // for ( FdFinancialStatements fdFinancialStatements : list ) {
        //     QueryWrapper<FdProjectFileCompound> queryWrapper = new QueryWrapper<>();
        //     queryWrapper.eq("project_id", fdFinancialStatements.getContractCode());
        //     List<FdProjectFileCompound> compoundList = fdProjectFileCompoundService.list(queryWrapper);
        //     for ( FdProjectFileCompound fdProjectFileCompound : compoundList ) {
        //         i++;
        //         compound += fdProjectFileCompound.getCompound();
        //         if (i<compoundList.size()){
        //             compound+=",";
        //         }
        //     }
        //     fdFinancialStatements.setCompoundName(compound);
        // }
        return list;
    }
    /**
     * @Author gurui
     * @Description //TODO 根据合同号查询已发付款通知书,但未收到款的合同
     * @Date 15:45 2019/7/25
     * @Param [contractId]
     * @return org.jeecg.modules.finance.entity.FdFinancialStatements
     **/
    @Override
    public List<FdFinancialStatements> queryByConId2(FdFinancialStatements financialStatements) {
        List<FdFinancialStatements> list = fdFinancialStatementsMapper.queryByConId2(financialStatements);
        // String compound = "";
        // Integer i = 0;
        // for ( FdFinancialStatements fdFinancialStatements : list ) {
        //     QueryWrapper<FdProjectFileCompound> queryWrapper = new QueryWrapper<>();
        //     queryWrapper.eq("project_id", fdFinancialStatements.getId());
        //     List<FdProjectFileCompound> compoundList = fdProjectFileCompoundService.list(queryWrapper);
        //     for ( FdProjectFileCompound fdProjectFileCompound : compoundList ) {
        //         i++;
        //         compound += fdProjectFileCompound.getCompound();
        //         if (i<compoundList.size()){
        //             compound+=",";
        //         }
        //     }
        //     fdFinancialStatements.setCompoundName(compound);
        // }
        return list;
    }


    /**
     * @Author gurui
     * @Description //TODO 导出json
     * @Date 15:45 2019/7/25
     * @Param [id]
     * @return org.jeecg.modules.finance.entity.FdFinancialStatements
     **/
    @Override
    public FdFinancialStatements export(String id) {
        FdFinancialStatements fdFinancialStatements = fdFinancialStatementsMapper.selectById(id);
        String contractPartyName = fdColumnManagementController.getContractPartyName(fdFinancialStatements.getPkContractParty());
        fdFinancialStatements.setContractPartyName(contractPartyName);
        LambdaQueryWrapper<FdPersonnel> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(FdPersonnel::getId,fdFinancialStatements.getBdId());
        FdPersonnel bdName = fdPersonnelService.getOne(queryWrapper);
        fdFinancialStatements.setBdName(bdName.getName());
        return fdFinancialStatements;
    }
}
