package com.zt.plat.module.contractorder.dal.mysql.contract;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.module.contractorder.api.vo.contract.FormulaRespVO;
import com.zt.plat.module.contractorder.dal.dataobject.contract.ContractFormulaDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 价款结算条款 Mapper
 *
 * @author 后台管理
 */
@Mapper
public interface ContractFormulaMapper extends BaseMapperX<ContractFormulaDO> {

    @Select({
            "<script>",
            "select ID id",
            ", CTRT_ID contractId",
            ", FMU_TP formulaType",
            ", FMU_CALT formulaCalculate",
            ", NUM_FMU numberFormula",
            ", MTRL_NAME materialName",
            ", MTRL_NUM materialNumber",
            ", DEC_PNT decimalPoint",
            ", ELEM_NUM elementNumber",
            ", ELEM_ABBR elementAbbreviation",
            ", ELEM_NAME elementName",
            ", STLM_TP settlementType",
            ", CREATE_TIME createTime",
            ", (select ctrt_name from BSE_CTRT_MAIN where id = ctrt_id) contractName",
            ", (select ctrt_ppr_num from BSE_CTRT_MAIN where id = ctrt_id) contractPaperNumber",
            "from bse_ctrt_fmu",
            "where DELETED = 0",
            "<if test= \"contractIds != null and contractIds.size() > 0\">",
            "and ctrt_id in",
            "<foreach collection = 'contractIds' item = 'contractId' open='(' separator = ',' close = ')'>",
            "#{contractId}",
            "</foreach>",
            "</if>",
            "<if test= \"formulaType != null and formulaType != ''\">",
            "and FMU_TP = #{formulaType}",
            "</if>",
            "<if test= \"materialName != null and materialName != ''\">",
            "and mtrl_name like concat('%',#{materialName},'%')",
            "</if>",
            "<if test= \"materialNumber != null and materialNumber != ''\">",
            "and MTRL_NUM like concat('%',#{materialNumber},'%')",
            "</if>",
            "<if test= \"elementAbbreviation != null and elementAbbreviation != ''\">",
            "and ELEM_ABBR like concat('%',#{elementAbbreviation},'%')",
            "</if>",
            "</script>"
    })
    IPage<FormulaRespVO> selectFormulas(IPage<?> page, List<Long> contractIds, String formulaType, String materialName, String materialNumber, String elementAbbreviation);
}