package thyyxxk.webserver.dao.his.targetmanagement;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import thyyxxk.webserver.entity.highreport.ZbReportCycleScore;

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

@Mapper
public interface ZbReportCycleScoreDao extends BaseMapper<ZbReportCycleScore> {

    @Select(" select * from zb_report_cycle_score where id = #{id} and report_cycle = #{reportCycle} ")
    ZbReportCycleScore selectZbReportCycleScoreByReportCycle(@Param("id") String id, @Param("reportCycle") String reportCycle);

    @Update("<script>" +
            "update zb_report_cycle_score " +
            "<trim prefix=\"set\" suffixOverrides=\",\">" +
            "<if test=\"id != null and id != '' \">" +
            "id = #{id}, " +
            "</if>" +
            "<if test=\"pid != null and pid != '' \">" +
            "pid = #{pid}, " +
            "</if>" +
            "<if test=\"reportCycle != null and reportCycle != '' \">" +
            "report_cycle = #{reportCycle}, " +
            "</if>" +
            "<if test=\"reportScore != null and reportScore != '' \">" +
            "report_score = #{reportScore}, " +
            "</if>" +
            "<if test=\"criterionScore != null and criterionScore != '' \">" +
            "criterion_score = #{criterionScore}, " +
            "</if>" +
            "<if test=\"authorId != null and authorId != '' \">" +
            "author_id = #{authorId}, " +
            "</if>" +
            "<if test=\"authorName != null and authorName != '' \">" +
            "author_name = #{authorName}, " +
            "</if>" +
            "<if test=\"authorScore != null and authorScore != '' \">" +
            "author_score = #{authorScore}, " +
            "</if>" +
            "<if test=\"mainId != null and mainId != '' \">" +
            "main_id = #{mainId}, " +
            "</if>" +
            "<if test=\"mainName != null and mainName != '' \">" +
            "main_name = #{mainName}, " +
            "</if>" +
            "<if test=\"yearRate != null and yearRate != '' \">" +
            "year_rate = #{yearRate}, " +
            "</if>" +
            "<if test=\"flag != null and flag != '' \">" +
            "flag = #{flag}, " +
            "</if>" +
            "</trim>" +
            "where id = #{id} and report_cycle = #{reportCycle} " +
            "</script>")
    int updateTargetReportScoreById(ZbReportCycleScore score);

    @Select(" select name from sys_parameters where code = 'targetScore' ")
    String selectScoreCyclePermissions();

    @Select("<script> " +
            "select zb.id, zb.pid, zb.name as t_name, zb.score, zb.method as t_method, " +
            "   zb.score_rule as t_rule, zb.op as t_manager, zb.op_id, " +
            "   isnull(s.report_score, '') + '/' + cast(cast(zb.score as float) as varchar) as t_score " +
            "from zb_zd_base_info zb left join zb_report_cycle_score s " +
            "on zb.id = s.id and zb.pid = s.pid and s.report_cycle = #{reportCycle} " +
            "where zb.pid = #{pid} " +
            "</script>")
    List<Map<String, Object>> selectTargetDictScoreByPid(@Param("pid") String pid, @Param("reportCycle") String reportCycle);

    @Select(" select * from zb_report_cycle_score where report_cycle = #{reportCycle} ")
    List<ZbReportCycleScore> selectTargetDictScoreByReportCycle(@Param("reportCycle") String reportCycle);

    @Update("<script>" +
            "update zb_report_cycle_score " +
            "<trim prefix=\"set\" suffixOverrides=\",\">" +
            "<if test=\"reportScore != null \">" +
            "report_score = #{reportScore}, " +
            "</if>" +
            "<if test=\"mainId != null and mainId != '' \">" +
            "main_id = #{mainId}, " +
            "</if>" +
            "<if test=\"mainName != null and mainName != '' \">" +
            "main_name = #{mainName}, " +
            "</if>" +
            "<if test=\"flag != null and flag != '' \">" +
            "flag = #{flag}, " +
            "</if>" +
            "</trim>" +
            "where id = #{id} and report_cycle = #{reportCycle} " +
            "</script>")
    int returnTargetReportScoreById(ZbReportCycleScore score);

}
