package com.rongwei.bscommon.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rongwei.bsentity.domain.ApsReportOutputDo;
import com.rongwei.rwadmincommon.system.domain.SysDictDo;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Entity com.rongwei.training.domain.ApsReportOutput
 */
public interface ApsReportOutputDao extends BaseMapper<ApsReportOutputDo> {

    @Select("SELECT\n" +
            "\td1.ID AS 'ID',\n" +
            "\tCONCAT( d2.NAME, \"_\", d1.NAME ) 'NAME' \n" +
            "FROM\n" +
            "\tsys_dict d1\n" +
            "\tLEFT JOIN sys_dict d2 ON d2.ID = d1.PID and d2.DELETED = 0\n" +
            "WHERE\n" +
            "d1.DELETED = 0\n" +
            "\tAND d1.DICTTYPE = 'quality_defects' \n" +
            "\tAND d2.ID != '724201d3c3454297bf90aa2df0335c1b'")
    List<SysDictDo> getQualityDefectsDictsByType();

    @Select("SELECT\n" +
            "  GROUP_CONCAT(\n" +
            "  CONCAT( OUTPUTDESCRIPT, '*', t.count_per_desc, '卷' )) AS OUTPUTDESC \n" +
            "FROM\n" +
            "  ( SELECT MAINID, ifnull( OUTPUTDESC, OUTPUTMATERIAL ) OUTPUTDESCRIPT, COUNT(*) count_per_desc FROM aps_report_output WHERE DELETED = '0' GROUP BY MAINID, OUTPUTDESCRIPT ) t \n" +
            "  WHERE MAINID = #{reportId}\n" +
            "GROUP BY\n" +
            "  MAINID")
    String selectDescByReportId(String reportId);
}




