<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zjrs.zwnw.sxgl.entity.RsJkHcpMapper">

	<select id="getHcpList" parameterType="com.zjrs.zwnw.sxgl.dto.HcpQueryDTO" resultType="com.zjrs.zwnw.sxgl.dto.HcpDTO">
		select rs_jk_hcp_lsh, sllsh, rs_wb_bj_lsh, evalprocess, pjqd, pjlx, 
			slbh, sbrxm, sbrsj, sjly, sxlb, sxmc, ssbmmc, to_char(blsj,'YYYY-MM-DD HH24:MI:SS') blsj,
			yhpj, yhpjnw, yhpjr, yhpjsj, xgpj, xgpjnw, tszt, tssj, 
			(select user_name from s_sg_user where id=y.xgpjr) xgpjr, xgpjsj, 
			case when trunc(blsj)+6 > trunc(sysdate) then '1' else '0' end sfkxg from (
				select a.rs_jk_hcp_lsh,a.sllsh,a.rs_wb_bj_lsh,a.evalprocess,a.pjqd,a.pjlx,
				b.slbh,b.sbrxm,b.sbrsj,b.sjly,c.sxlb,c.sxmc,c.ssbmmc,case when a.evalprocess='1' then
				(select to_date(to_char(bae003),'YYYY-MM-DD HH24:MI:SS') from wf_process_instance where bae007=b.ywlsh) else
				(select to_date(to_char(complete_time),'YYYY-MM-DD HH24:MI:SS') from wf_process_instance where bae007=b.ywlsh) end blsj,
				a.yhpj,a.yhpjnw,a.yhpjr,a.yhpjsj,a.xgpj,a.xgpjnw,a.xgpjr,a.xgpjsj,a.tszt,a.tssj
				from rs_jk_hcp a,rs_slxx b,rs_sx_config c 
				where a.sllsh=b.sllsh and b.sbsx=c.sxbm and a.sllsh is not null) y 
		where 1=1
		<if test="dto.rsJkHcpLsh != null and dto.rsJkHcpLsh != ''">
            and rs_jk_hcp_lsh = #{dto.rsJkHcpLsh}
        </if>
        <if test="dto.slbh != null and dto.slbh != ''">
            and slbh = #{dto.slbh}
        </if>
        <if test="dto.tssjz != null and dto.tssjz != ''">
            and substr(tssj,1,10) &lt;= #{dto.tssjz}
        </if>
        order by yhpjsj DESC 
    </select>
    
    <select id="getSlxx" parameterType="com.zjrs.zwnw.sxgl.dto.HcpCkQueryDTO" resultType="com.zjrs.zwnw.sxgl.dto.HcpCkDTO">
    	select a.slbh,b.sxmc,nvl(b.sfjbsx,'0') sfjbsx,case when (select count(1) from wf_process_instance 
			where bae007=a.ywlsh ) > 0 then '2' else '1' end evalprocess,
			case when a.sjly!='1' then (select rs_wb_bj_lsh from rs_wb_bj where sllsh=a.sllsh) else '' end rs_wb_bj_lsh 
		from rs_slxx a,rs_sx_config b where a.sbsx=b.sxbm and a.sllsh=#{dto.sllsh}
    </select>

</mapper>
