package com.sunda.spmsoversea.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sunda.spmsoversea.dto.OverseaWerksCostQueryDTO;
import com.sunda.spmsoversea.entity.OverseaWerksCost;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

/**
 * <p>
 * 工厂车间映射成本中心配置 Mapper 接口
 * </p>
 *
 * @author Hzc
 * @since 2022-12-06
 */
@Mapper
public interface OverseaWerksCostMapper extends BaseMapper<OverseaWerksCost> {


    @Select("<script>" +
            "SELECT OW.UUID AS \"uuid\",\n" +
            "       OW.WERKS AS \"werks\",\n" +
            "       OW.WHS_LOCATION_CODE AS \"whsLocationCode\",\n" +
            "       OW.COST_CENTER AS \"costCenter\",\n" +
            "       cc.COST_CENTER_NAME AS \"costCenterName\",\n" +
            "       OW.CREATE_DATE AS \"createDate\",\n" +
            "       OW.WORK_CODE AS \"workCode\",\n" +
            "       OW.SPMS_STATUS AS \"spmsStatus\",\n" +
            "       cc.COST_CENTER_EN_NAME AS \"costCenterEnName\",\n" +
            "       OW.UPDATE_DATE AS \"updateDate\"\n" +
            "FROM OVERSEA_WERKS_COST  OW " +
            "  LEFT JOIN COST_CENTER cc on OW.COST_CENTER=cc.COST_CENTER_CODE \n" +
            "WHERE OW.SPMS_STATUS != '0' " +
            " <when test='dto.werks!=null and dto.werks != \"\"'> AND OW.WERKS = #{dto.werks}</when>" +
            " <when test='dto.whsLocationCode!=null and dto.whsLocationCode != \"\"'> AND OW.WHS_LOCATION_CODE = #{dto.whsLocationCode}</when>" +
            " <when test='dto.costCenter!=null and dto.costCenter != \"\"'> AND OW.COST_CENTER = #{dto.costCenter}</when>" +
            " <when test='dto.costCenterName!=null and dto.costCenterName != \"\"'> AND OW.COST_CENTER_NAME = #{dto.costCenterName}</when>" +
            " ORDER BY OW.CREATE_DATE DESC " +
            "</script>")
    List<Map<String, Object>> getOverseaWerksCostPage(IPage page, @Param("dto") OverseaWerksCostQueryDTO dto);
}
