<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, hnqz All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the pig4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: hnqz
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.qunzhixinxi.hnqz.admin.mapper.WmTaskMapper">

	<resultMap id="wmTaskMap" type="com.qunzhixinxi.hnqz.admin.entity.WmTask">
		<id property="id" column="id"/>
		<result property="taskTypeId" column="task_type_id"/>
		<result property="taskRuleId" column="task_rule_id"/>
		<result property="score" column="score"/>
		<result property="scorePackageDrugId" column="score_package_drug_id"/>
		<result property="scorePackageId" column="score_package_id"/>
		<result property="scoreDrugId" column="score_drug_id"/>
		<result property="lookintoDate" column="lookinto_date"/>
		<result property="province" column="province"/>
		<result property="city" column="city"/>
		<result property="area" column="area"/>
		<result property="address" column="address"/>
		<result property="lookintoTypeId" column="lookinto_type_id"/>
		<result property="taskContentId" column="task_content_id"/>
		<result property="taskStatus" column="task_status"/>
		<result property="submitStatus" column="submit_status"/>
		<result property="taskUserId" column="task_user_id"/>
		<result property="taskUserType" column="task_user_type"/>
		<result property="drugEntId" column="drug_ent_id"/>
		<result property="deptId" column="dept_id"/>
		<result property="delFlag" column="del_flag"/>
		<result property="enableFlag" column="enable_flag"/>
		<result property="tenantId" column="tenant_id"/>
		<result property="createTime" column="create_time"/>
		<result property="createUser" column="create_user"/>
		<result property="updateTime" column="update_time"/>
		<result property="updateUser" column="update_user"/>
		<result property="shareImgUrl" column="share_img_url"/>
		<result property="platAuditStatus" column="plat_audit_status"/>
		<result property="scorePackageLevel1Id" column="score_package_level1_id"/>
		<result property="taskInfoImg" column="task_info_img"/>
		<result property="compareResult" column="compare_result"/>
		<result property="approvalOpinion" column="approval_opinion"/>
		<result property="approvalInfo" column="approval_info"/>
		<result property="realFlag" column="real_flag"/>
		<result property="reportOneId" column="report_one_id"/>
		<result property="reportOneApprovalStatus" column="report_one_approval_status"/>
		<result property="reportOneApprovalOpinion" column="report_one_approval_opinion"/>
		<result property="reportOneApprovalInfo" column="report_one_approval_info"/>
		<result property="reportSecondId" column="report_second_id"/>
		<result property="reportSecondApprovalStatus" column="report_second_approval_status"/>
		<result property="reportSecondApprovalOpinion" column="report_second_approval_opinion"/>
		<result property="reportSecondApprovalInfo" column="report_second_approval_info"/>
		<result property="reportDrugId" column="report_drug_id"/>
		<result property="reportDrugApprovalStatus" column="report_drug_approval_status"/>
		<result property="reportDrugApprovalOpinion" column="report_drug_approval_opinion"/>
		<result property="reportDrugApprovalInfo" column="report_drug_approval_info"/>
		<result property="taskStatusInfo" column="task_status_info"/>
		<result property="taskFrom" column="task_from"/>

	</resultMap>

	<resultMap id="wmTaskWithContentMap" type="com.qunzhixinxi.hnqz.admin.entity.WmTask">
		<id property="id" column="id"/>
		<result property="taskTypeId" column="task_type_id"/>
		<result property="taskRuleId" column="task_rule_id"/>
		<result property="score" column="score"/>
		<result property="scorePackageDrugId" column="score_package_drug_id"/>
		<result property="scorePackageId" column="score_package_id"/>
		<result property="scoreDrugId" column="score_drug_id"/>
		<result property="lookintoDate" column="lookinto_date"/>
		<result property="province" column="province"/>
		<result property="city" column="city"/>
		<result property="area" column="area"/>
		<result property="address" column="address"/>
		<result property="lookintoTypeId" column="lookinto_type_id"/>
		<result property="taskContentId" column="task_content_id"/>
		<result property="taskStatus" column="task_status"/>
		<result property="submitStatus" column="submit_status"/>
		<result property="taskUserId" column="task_user_id"/>
		<result property="taskUserType" column="task_user_type"/>
		<result property="drugEntId" column="drug_ent_id"/>
		<result property="deptId" column="dept_id"/>
		<result property="delFlag" column="del_flag"/>
		<result property="enableFlag" column="enable_flag"/>
		<result property="tenantId" column="tenant_id"/>
		<result property="createTime" column="create_time"/>
		<result property="createUser" column="create_user"/>
		<result property="updateTime" column="update_time"/>
		<result property="updateUser" column="update_user"/>
		<result property="shareImgUrl" column="share_img_url"/>
		<result property="platAuditStatus" column="plat_audit_status"/>
		<result property="scorePackageLevel1Id" column="score_package_level1_id"/>
		<result property="taskInfoImg" column="task_info_img"/>
		<result property="compareResult" column="compare_result"/>
		<result property="approvalOpinion" column="approval_opinion"/>
		<result property="approvalInfo" column="approval_info"/>
		<result property="realFlag" column="real_flag"/>
		<result property="reportOneId" column="report_one_id"/>
		<result property="reportOneApprovalStatus" column="report_one_approval_status"/>
		<result property="reportOneApprovalOpinion" column="report_one_approval_opinion"/>
		<result property="reportOneApprovalInfo" column="report_one_approval_info"/>
		<result property="reportSecondId" column="report_second_id"/>
		<result property="reportSecondApprovalStatus" column="report_second_approval_status"/>
		<result property="reportSecondApprovalOpinion" column="report_second_approval_opinion"/>
		<result property="reportSecondApprovalInfo" column="report_second_approval_info"/>
		<result property="reportDrugId" column="report_drug_id"/>
		<result property="reportDrugApprovalStatus" column="report_drug_approval_status"/>
		<result property="reportDrugApprovalOpinion" column="report_drug_approval_opinion"/>
		<result property="reportDrugApprovalInfo" column="report_drug_approval_info"/>
		<result property="taskStatusInfo" column="task_status_info"/>
		<result property="taskFrom" column="task_from"/>
		<association property="wmTaskContent" javaType="com.qunzhixinxi.hnqz.admin.entity.WmTaskContent">
			<result property="temp1" column="temp1"/>
			<result property="temp2" column="temp2"/>
			<result property="temp3" column="temp3"/>
			<result property="temp4" column="temp4"/>
			<result property="temp5" column="temp5"/>
			<result property="temp6" column="temp6"/>
			<result property="temp7" column="temp7"/>
			<result property="temp8" column="temp8"/>
			<result property="temp9" column="temp9"/>
			<result property="temp10" column="temp10"/>
			<result property="temp11" column="temp11"/>
			<result property="temp12" column="temp12"/>
			<result property="temp13" column="temp13"/>
			<result property="temp14" column="temp14"/>
			<result property="temp15" column="temp15"/>
			<result property="temp16" column="temp16"/>
			<result property="temp17" column="temp17"/>
			<result property="temp18" column="temp18"/>
			<result property="temp19" column="temp19"/>
			<result property="temp20" column="temp20"/>
			<result property="temp21" column="temp21"/>
			<result property="temp22" column="temp22"/>
			<result property="temp23" column="temp23"/>
			<result property="temp24" column="temp24"/>
			<result property="temp25" column="temp25"/>
			<result property="temp26" column="temp26"/>
			<result property="temp28" column="temp28"/>
			<result property="temp29" column="temp29"/>
			<result property="temp30" column="temp30"/>
			<result property="temp31" column="temp31"/>
			<result property="temp32" column="temp32"/>
		</association>
	</resultMap>

	<select id="selectListByExtEnt" resultMap="wmTaskMap">
		SELECT
		wm_task.*
		FROM
		wm_task,
		wm_task_content
		<where>
			wm_task.task_content_id = wm_task_content.id
			and wm_task.del_flag='0' and wm_task.enable_flag='0'


			<if test="query.extIds != null and query.extIds.size()>0">
				AND wm_task.task_content_id in (

				<foreach collection="query.extIds" item="pid" index="index">
					select id from wm_task_content where wm_task_content.temp1  LIKE CONCAT('%',#{pid},'%')
					<if test="query.extIds.size()>1">
						<if test="query.extIds.size()>index-1">
							union
						</if>
					</if>
				</foreach>

				)
			</if>

			<if test="query.createTime != null and query.createTime != ''">
				AND <![CDATA[ wm_task.create_time>= #{query.createTime}]]>
			</if>

			<if test="query.updateTime != null and query.updateTime != ''">
				AND <![CDATA[ wm_task.update_time<=#{query.updateTime}]]>
			</if>

			<if test="query.drugEntId != null and query.drugEntId != ''">
				AND <![CDATA[ wm_task.drug_ent_id=#{query.drugEntId}]]>
			</if>
		</where>
	</select>


	<select id="selectListByExtEntNoPage" resultMap="wmTaskMap">
		SELECT
		wm_task.*
		FROM
		wm_task,
		wm_task_content
		<where>
			wm_task.task_content_id = wm_task_content.id
			and wm_task.del_flag='0' and wm_task.enable_flag='0'


			<if test="query.extIds != null and query.extIds.size()>0">
				AND wm_task.task_content_id in (

				<foreach collection="query.extIds" item="pid" index="index">
					select id from wm_task_content where wm_task_content.temp1  LIKE CONCAT('%',#{pid},'%')
					<if test="query.extIds.size()>1">
						<if test="query.extIds.size()>index-1">
							union
						</if>
					</if>
				</foreach>

				)
			</if>



			<if test="query.createTime != null and query.createTime != ''">
				AND <![CDATA[ wm_task.create_time>= #{query.createTime}]]>
			</if>

			<if test="query.updateTime != null and query.updateTime != ''">
				AND <![CDATA[ wm_task.update_time<=#{query.updateTime}]]>
			</if>

			<if test="query.drugEntId != null and query.drugEntId != ''">
				AND <![CDATA[ wm_task.drug_ent_id<=#{query.drugEntId}]]>
			</if>
		</where>
	</select>


	<select id="getTaskListByPackageIds" resultType="java.util.HashMap">
		select * from (SELECT
		package_id,
		score_name,
		base_id,
		sum(score) score,
		count(1) score_count,
		realname,
		dept_name,
		DATE_FORMAT(max( create_time ),'%Y-%m-%d') create_time
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		group by
		package_id,
		score_name,
		base_id,
		realname,
		dept_name
		) a ORDER BY  a.dept_name,a.score_name,a.realname
	</select>

	<select id="getTaskListByPackageIdsAndUser" resultType="java.util.HashMap">
		SELECT
		*
		FROM
		(
		SELECT
		score_name,
		sum( score ) score,
		count( 1 ) score_count,
		realname,
		dept_name
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		GROUP BY
		score_name,
		dept_name,
		realname
		) A
		ORDER BY
		A.dept_name,
		a.score_name,
		a.realname
	</select>


	<select id="getTaskListByPackageIdsCount" resultType="java.util.HashMap">
		SELECT
		base_id taskTypeName,
		sum( score ) taskSum,
		count( 1 ) taskCount
		FROM
		wm_zb_count
		WHERE
		package_id IN (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)

		GROUP BY
		base_id
	</select>

	<select id="getTaskListByPackageIdsZd" resultType="java.util.HashMap">
		SELECT
		DATE_FORMAT(min( create_time ),'%Y-%m-%d') mindate,
		DATE_FORMAT(max( create_time ),'%Y-%m-%d') maxdate,
		GROUP_CONCAT( DISTINCT realname ) realname,
		sum( score ) sumscore,
		GROUP_CONCAT( DISTINCT task_rule_id ) task_rule_id
		FROM
		wm_zb_count
		where package_id IN (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		or
		package_id IN (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
	</select>





	<select id="getTaskListByPackageIdsReturnWmtaskInfo" resultMap="wmTaskMap">
		SELECT
		*
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)

		order by task_user_id asc,create_time asc

	</select>

	<select id="selectZbCount" resultType="java.util.HashMap">
		select * from (select * from (SELECT
		package_id,
		score_name,
		send_package_dept_id,
		dept_id,
		sum(score) score,
		count(1) score_count,
		realname,
		dept_name,
		DATE_FORMAT(max( create_time ),'%Y-%m-%d') create_time,
		DATE_FORMAT(max( pcreate_time ),'%Y-%m-%d') pcreate_time
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		group by
		package_id,
		score_name,
		send_package_dept_id,
		dept_id,
		package_score,
		realname,
		dept_name
		) a ORDER BY  a.dept_name,a.score_name,a.realname ) b
	</select>

	<select id="selectByWmTaskOne" resultType="java.util.HashMap">
		select
		sum(score) score,
		count(1) score_count,
		dept_id,
		report_one_approval_status,
		score_package_id
		from wm_task
		where  score_package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
	</select>
	<select id="selectByWmTaskSecond" resultType="java.util.HashMap">
		select
		sum(score) score,
		count(1) score_count,
		dept_id,
		report_second_approval_status,
		score_package_id
		from wm_task
		where  score_package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
	</select>
	<select id="selectByWmTaskDrug" resultType="java.util.HashMap">
		select
		sum(score) score,
		count(1) score_count,
		dept_id,
		report_drug_approval_status,
		score_package_id
		from wm_task
		where  score_package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
	</select>

	<select id="selectByWmTaskId" resultMap="wmTaskMap">
		select
		*
		from wm_task
		where
		score_package_id = #{query.scorePackageId,jdbcType=VARCHAR}
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
		and
		del_flag =0
   		and
   		enable_flag=0
	</select>

	<select id="selectByReportOneApprovalStatus" resultType="java.util.HashMap">
		select
		sum(score) score,
		count(1) score_count,
		dept_id,
		report_one_approval_status,
		score_package_id
		from wm_task
		where  score_package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
		and
		report_one_approval_status = #{query.reportOneApprovalStatus,jdbcType=VARCHAR}
		group by dept_id, report_one_approval_status, score_package_id
	</select>

	<select id="selectByReportSecondApprovalStatus" resultType="java.util.HashMap">
		select
		sum(score) score,
		count(1) score_count,
		dept_id,
		report_second_approval_status,
		score_package_id
		from wm_task
		where  score_package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
		and
		report_second_approval_status = #{query.reportSecondApprovalStatus,jdbcType=VARCHAR}
		group by dept_id, report_second_approval_status, score_package_id
	</select>

	<select id="selectByReportDrugApprovalStatus" resultType="java.util.HashMap">
		select
		sum(score) score,
		count(1) score_count,
		dept_id,
		report_drug_approval_status,
		score_package_id
		from wm_task
		where  score_package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
		and
		report_drug_approval_status = #{query.reportDrugApprovalStatus,jdbcType=VARCHAR}
		group by dept_id, report_drug_approval_status, score_package_id
	</select>
	<select id="selectById" resultMap="wmTaskMap">
		select
		*
		from wm_task
		where
		id = #{query.Id,jdbcType=BIGINT}
	</select>

	<select id="selectByRealFlag" resultMap="wmTaskMap">
		select
		*
		from wm_task
		where
		id = #{Id,jdbcType=BIGINT}
		and real_flag = 0
	</select>

	<select id="selectWmTaskById" resultMap="wmTaskMap">
		select
		*
		from wm_task
		where
		id = #{query.id,jdbcType=BIGINT}
		and
		task_status = #{query.taskStatus,jdbcType=VARCHAR}
	</select>
	<select id="selectListByIds" resultMap="wmTaskMap">
   		SELECT
   		*
   		FROM
   		wm_task
   		where
   		score_package_id = #{query.scorePackageId,jdbcType=VARCHAR}
   		and real_flag = 0
</select>
	<select id="selectListByScorePackageId" resultMap="wmTaskMap">
   		SELECT
   		*
   		FROM
   		wm_task
   		where
   		score_package_id = #{query.scorePackageId,jdbcType=VARCHAR}
   		and
   		task_status = #{query.taskStatus,jdbcType=VARCHAR}
   		and
   		del_flag =0
   		and
   		enable_flag=0
</select>
	<select id="getTaskListByPackageIdsForJs" resultType="java.util.HashMap">
		select * from (select * from (SELECT
		package_id,
		score_name,
		package_score,
		sum(score) score,
		count(1) score_count,
		realname,
		dept_name,
		DATE_FORMAT(max( create_time ),'%Y-%m-%d') create_time,
		DATE_FORMAT(max( pcreate_time ),'%Y-%m-%d') pcreate_time
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		group by
		package_id,
		score_name,
		package_score,
		realname,
		dept_name
		) a ORDER BY  a.dept_name,a.score_name,a.realname ) b

		union

		SELECT
		"" package_id,
		"" score_name,
		package_score,
		sum(score) score,
		count(1) score_count,
		"合计" realname,
		"" dept_name,
		"" create_time,
		"" pcreate_time
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
	</select>

	<select id="getTaskListByPackageIdsForJsUser" resultType="java.util.HashMap">
		select * from (SELECT
		*
		FROM
		(
		SELECT
		sum( score ) score,
		count( 1 ) score_count,
		user_id,
		realname,
		phone,
		dept_name,
		DATE_FORMAT( max( create_time ), '%Y-%m-%d' ) create_time
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		GROUP BY
		user_id,
		realname,
		phone,
		dept_name
		) a
		ORDER BY
		a.dept_name,
		a.realname) bb
		UNION
		SELECT
		sum( score ) score,
		count( 1 ) score_count,
		"" user_id,
		"合计" realname,
		"" phone,
		""dept_name,
		"" create_time
		FROM
		wm_zb_count
		where  package_id in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
	</select>




	<select id="getH5PackageList" resultType="java.util.HashMap">
		SELECT
		p.id id ,
		p.score_package_name as score_name,u.realname,
	   	p.package_type1 as type1,
		u.phone,
		u.user_id as userId,
		sum( ifnull(t.score, 0) ) taskSum,
		count( 1 ) taskCount
		FROM
		wm_task t
		left join wm_score_package p on p.id=t.score_package_id
		left join sys_user u on u.user_id=t.task_user_id
		where  p.score_package_name in (
		<foreach collection="query.extIds" item="pid" index="index" separator=",">
			#{pid}
		</foreach>
		)
		and t.task_status=3
		and t.del_flag=0
		and t.enable_flag=0
		GROUP BY
		p.id,p.score_package_name,u.realname,u.phone
	</select>



	<select id="getH5TaskList" resultType="java.util.HashMap">
		SELECT
		t.id id ,
		p.score_package_name  as score_name,
		p.package_type2 as `type`,
		p.package_type1 as type1,
		u.realname,
		e.task_type_name,
		DATE_FORMAT( t.create_time, '%Y-%m-%d' ) create_time,
		ifnull(t.score, 0) taskSum,
		ifnull(t.score, 0) taskCount
		FROM
		wm_task t
		left join wm_score_package p on p.id=t.score_package_id
		left join sys_user u on u.user_id=t.task_user_id
		left join wm_task_type e on e.id=t.task_type_id
		where  p.id = #{query.scorePackageId}
		and t.task_status=3
		and t.task_user_id= #{query.taskUserId}
		and t.del_flag=0
		and t.enable_flag=0
		ORDER BY
		t.create_time DESC

</select>


	<select id="getTaskListByIds" resultType="java.util.HashMap">
		select * from (
		SELECT
		p.id AS package_id,
		p.score_package_name AS score_name,
		c.realname AS realname,
		d.name AS dept_name,
		m.label AS base_id,
		sum(t.score) score,
		count(1) score_count,
		DATE_FORMAT(max( t.lookinto_date ),'%Y-%m-%d') create_time
		FROM wm_task t
		LEFT JOIN wm_score_package p ON t.score_package_id = p.id
		JOIN wm_task_type b
		left join sys_dict_item m on m.type='score_task_type' and b.parent_id=m.`value`
		JOIN sys_user c
		JOIN sys_dept d
		WHERE b.id = t.task_type_id
		AND c.user_id = t.task_user_id
		AND c.dept_id = d.dept_id
		and t.task_status=3
		and t.enable_flag=0
		and t.del_flag=0
		and t.real_flag = '0'
		<if test="query.id!=null and query.id!=''">
			AND t.id in(${query.id})
		</if>
		group by
		p.id,
		p.score_package_name,
		m.label,
		c.realname,
		d.name
		)a ORDER BY a.dept_name,a.score_name,a.realname
	</select>

	<select id="getTaskListByIdsOld" resultType="java.util.HashMap">
		select * from (
		SELECT
		p.id AS package_id,
		p.score_package_name AS score_name,
		c.realname AS realname,
		d.name AS dept_name,
		m.label AS base_id,
		sum(t.score) score,
		count(1) score_count,
		DATE_FORMAT(max( t.lookinto_date ),'%Y-%m-%d') create_time
		FROM wm_task t
		LEFT JOIN wm_score_package p ON t.score_package_drug_id = p.id
		JOIN wm_task_type b
		left join sys_dict_item m on m.type='score_task_type' and b.parent_id=m.`value`
		JOIN sys_user c
		JOIN sys_dept d
		WHERE b.id = t.task_type_id
		AND c.user_id = t.task_user_id
		AND c.dept_id = d.dept_id
		and t.task_status=3
		and t.enable_flag=0
		and t.del_flag=0
		and t.real_flag = '0'
		<if test="query.id!=null and query.id!=''">
			AND t.id in(${query.id})
		</if>
		group by
		p.id,
		p.score_package_name,
		m.label,
		c.realname,
		d.name
		)a ORDER BY a.dept_name,a.score_name,a.realname
	</select>

	<select id="getTaskListByIdsJs" resultType="java.util.HashMap">
		select * from (
		SELECT
		p.id AS package_id,
		p.score_package_name AS score_name,
		c.realname AS realname,
		d.name AS dept_name,
		m.label AS base_id,
		sum(t.score) score,
		count(1) score_count,
		DATE_FORMAT(max( t.lookinto_date ),'%Y-%m-%d') create_time
		FROM wm_task t
		LEFT JOIN wm_score_package p ON t.score_package_id = p.id
		JOIN wm_task_type b
		left join sys_dict_item m on m.type='score_task_type' and b.parent_id=m.`value`
		JOIN sys_user c
		JOIN sys_dept d
		WHERE b.id = t.task_type_id
		AND c.user_id = t.task_user_id
		and d.dept_id=t.dept_id
		and t.task_status=3
		and t.enable_flag=0
		and t.del_flag=0
		and p.package_type2=2
		<if test="query.id!=null and query.id!=''">
			AND t.id in(${query.id})
		</if>
		group by
		p.id,
		p.score_package_name,
		m.label,
		c.realname,
		d.name
		)a ORDER BY a.dept_name,a.score_name,a.realname
	</select>


	<select id="getTaskListByIdsReturnWmtaskInfo" resultMap="wmTaskMap">
		SELECT
		t.id AS id,
		t.task_rule_id AS task_rule_id,
		t.score AS score,
		t.score_package_drug_id AS score_package_drug_id,
		t.score_package_level1_id AS score_package_level1_id,
		t.score_package_id AS score_package_id,
		t.task_type_id AS task_type_id,
		t.lookinto_date AS lookinto_date,
		t.province AS province,
		t.city AS city,
		t.area AS area,
		t.address AS address,
		t.lookinto_type_id AS lookinto_type_id,
		t.task_content_id AS task_content_id,
		t.task_status AS task_status,
		t.task_user_id AS task_user_id,
		t.task_user_type AS task_user_type,
		t.drug_ent_id AS drug_ent_id,
		t.dept_id AS dept_id,
		t.del_flag AS del_flag,
		t.enable_flag AS enable_flag,
		t.tenant_id AS tenant_id,
		t.lookinto_date AS create_time,
		t.create_user AS create_user,
		t.update_time AS update_time,
		t.update_user AS update_user,
		t.submit_status AS submit_status,
		t.share_img_url AS share_img_url,
		t.plat_audit_status AS plat_audit_status,
		t.ext_ids AS ext_ids,
		t.task_info_img AS task_info_img
		FROM wm_task t
		where 1=1
		<if test="query.id!=null and query.id!=''">
			AND t.id in(${query.id})
		</if>
		order by t.task_user_id asc,t.create_time asc
	</select>

	<select id="getTaskListByIdsCount" resultType="java.util.HashMap">
		SELECT
		m.label AS taskTypeName,
		sum( t.score ) taskSum,
		count( 1 ) taskCount
		FROM wm_task t
		LEFT JOIN wm_score_package p ON t.score_package_id = p.id
		JOIN wm_task_type b
		left join sys_dict_item m on m.type='score_task_type' and m.`value`=b.parent_id
		WHERE b.id = t.task_type_id
		and t.task_status=3
		and t.enable_flag=0
		and t.del_flag=0
		<if test="query.id!=null and query.id!=''">
			AND t.id in(${query.id})
		</if>
		GROUP BY
		m.label
	</select>

	<select id="getTaskListByIdsZd" resultType="java.util.HashMap">
		SELECT
		DATE_FORMAT(min( t.lookinto_date ),'%Y-%m-%d') mindate,
		DATE_FORMAT(max( t.lookinto_date ),'%Y-%m-%d') maxdate,
		GROUP_CONCAT( DISTINCT c.realname ) realname,
		sum( t.score ) sumscore,
		GROUP_CONCAT( DISTINCT t.task_rule_id ) task_rule_id
		FROM wm_task t
		LEFT JOIN wm_score_package p ON t.score_package_id = p.id
		JOIN wm_task_type b
		JOIN sys_user c
		JOIN sys_dept d
		WHERE b.id = t.task_type_id
		AND c.user_id = t.task_user_id
		AND c.dept_id = d.dept_id
		and t.task_status=3
		and t.enable_flag=0
		and t.del_flag=0
		<if test="query.id!=null and query.id!=''">
			AND t.id in(${query.id})
		</if>
		ORDER BY
		t.task_rule_id,
		t.task_user_id,
		t.lookinto_date

	</select>

	<select id="getTaskListByIdsZdJs" resultType="java.util.HashMap">
		SELECT
		DATE_FORMAT(min( t.lookinto_date ),'%Y-%m-%d') mindate,
		DATE_FORMAT(max( t.lookinto_date ),'%Y-%m-%d') maxdate,
		GROUP_CONCAT( DISTINCT c.realname ) realname,
		sum( t.score ) sumscore,
		GROUP_CONCAT( DISTINCT t.task_rule_id ) task_rule_id
		FROM wm_task t
		LEFT JOIN wm_score_package p ON t.score_package_id = p.id
		JOIN wm_task_type b
		JOIN sys_user c
		JOIN sys_dept d
		WHERE b.id = t.task_type_id
		AND c.user_id = t.task_user_id
		AND t.dept_id = d.dept_id
		and t.task_status=3
		and t.enable_flag=0
		and t.del_flag=0
		and p.package_type2=2
		<if test="query.id!=null and query.id!=''">
			AND t.id in(${query.id})
		</if>
		ORDER BY
		t.task_rule_id,
		t.task_user_id,
		t.lookinto_date

	</select>

	<select id="getWmTaskList" resultMap="wmTaskMap">
		SELECT
		t.id AS id,
		t.task_rule_id AS task_rule_id,
		t.score AS score,
		p2.id AS score_package_drug_id,
		p1.id AS score_package_level1_id,
		p.score_package_name AS score_package_id,
		t.task_type_id AS task_type_id,
		t.lookinto_date AS lookinto_date,
		t.province AS province,
		t.city AS city,
		t.area AS area,
		t.address AS address,
		t.lookinto_type_id AS lookinto_type_id,
		t.task_content_id AS task_content_id,
		t.task_status AS task_status,
		u.realname AS task_user_id,
		t.task_user_type AS task_user_type,
		t.drug_ent_id AS drug_ent_id,
		d.`name` AS dept_id,
		t.del_flag AS del_flag,
		t.enable_flag AS enable_flag,
		t.tenant_id AS tenant_id,
		t.lookinto_date AS create_time,
		t.create_user AS create_user,
		t.update_time AS update_time,
		t.update_user AS update_user,
		t.submit_status AS submit_status,
		t.share_img_url AS share_img_url,
		t.plat_audit_status AS plat_audit_status,
		t.task_info_img AS task_info_img
		FROM wm_task t
		left join sys_user u on  u.user_id=t.task_user_id
		left join sys_dept d on d.dept_id=t.dept_id
		left join wm_score_package p on p.id=t.score_package_id
		left join wm_score_package p1 on p1.id=t.score_package_level1_id
		left join wm_score_package p2 on p1.id=t.score_package_drug_id
		where t.del_flag=0
		and t.real_flag=0
		and t.task_status !='1'
		<if test="query.scorePackageDrugId!=null and query.scorePackageDrugId!=''">
			and t.score_package_drug_id = #{query.scorePackageDrugId}
		</if>
		<if test="query.scorePackageLevel1Id!=null and query.scorePackageLevel1Id!=''">
			and t.score_package_level1_id = #{query.scorePackageLevel1Id}
		</if>
		<if test="query.scorePackageId!=null and query.scorePackageId!=''">
			and  t.score_package_id = #{query.scorePackageId}
		</if>
		<if test="query.id!=null and query.id!=''">
			and  t.id = #{query.id}
		</if>
		<if test="query.taskStatus!=null and query.taskStatus!=''">
			and  t.task_status = #{query.taskStatus}
		</if>
		<if test="query.taskUserId!=null and query.taskUserId!=''">
			and  t.task_user_id = #{query.taskUserId}
		</if>
		order by t.lookinto_date

	</select>


	<select id="selectByTask" resultMap="wmTaskMap">
		select t.* FROM wm_task t
		where t.del_flag=0
		<if test="query.id!=null and query.id!=''">
			and  t.id = #{query.id}
		</if>
		<if test="query.scorePackageId!=null and query.scorePackageId!=''">
			and  t.score_package_id = #{query.scorePackageId}
		</if>
		<if test="query.taskUserId!=null and query.taskUserId!=''">
			and  t.task_user_id = #{query.taskUserId}
		</if>
		<if test="query.enableFlag!=null and query.enableFlag!=''">
			and  t.enable_flag in (${query.enableFlag})
		</if>


	</select>

	<select id="PackageIsFinishByTask" resultType="java.util.HashMap">
	SELECT
	tt.*
FROM
	(
	SELECT
		b.num,
		a.task_num,
		b.scoreSum,
		a.user_score,
	CASE

			WHEN b.package_type1 = '1' THEN
			b.user_score - b.scoreSum
			WHEN (b.package_type1 = '2' or b.package_type1 = '3') THEN
			b.task_num - b.num ELSE '1'
		END AS isFinish,
		a.id
	FROM
		wm_score_package_status a
		LEFT JOIN (
		SELECT
			s.id,
			p.package_type1,
			count( t.id ) AS num,
			sum( t.score ) AS scoreSum ,
			case when s.user_score is null then p.score else s.user_score end as user_score,
			case when s.task_num is null then p.task_num else s.task_num end as task_num
		FROM
			wm_score_package_status s
			LEFT JOIN wm_score_package p ON s.package_id = p.id
			LEFT JOIN wm_task t ON t.score_package_id = p.id
			AND s.user_id = t.task_user_id
		WHERE
			s.del_flag = 0
			AND s.enable_flag = 0
			AND s.`status` != 3
			AND p.del_flag = 0
			AND t.del_flag = 0
			AND t.task_status = 3
			AND p.id = #{query.scorePackageId}
		GROUP BY
			s.id,
			p.package_type1
		) b ON a.id = b.id
	WHERE
		a.del_flag = 0
		AND a.`status` != 3
		AND a.enable_flag = 0
	AND a.package_id = #{query.scorePackageId}
	) tt
	</select>

	<select id="getMaxCreateTime" resultType="java.util.HashMap">
	select max(t.lookinto_date) as MaxTime from wm_task t
	where 1=1
	<if test="query.id!=null and query.id!=''">
		AND t.id in(${query.id})
	</if>
	</select>

	<select id="selectListByWmTask" resultMap="wmTaskMap">
	select * from wm_task where score_package_id
	in (
	select id from wm_score_package where id = #{query.id}
	union all
	select id from wm_score_package where relation_score_id = #{query.id}
	union all
	select id from wm_score_package where relation_score_id in (select id from wm_score_package where relation_score_id = #{query.id})
	union all
	select id from wm_score_package where relation_score_id in (select id from wm_score_package where relation_score_id in (select id from wm_score_package where relation_score_id = #{query.id}))
	)
	and task_status=3
	and (
	(report_drug_approval_status in ( 5,6)  and report_drug_approval_opinion = 1)
	 or (report_one_approval_status in ( 5,6)and report_one_approval_opinion = 1)
	 )
	</select>


	<select id="selectSettleTask" resultType="java.util.HashMap">
		select t.id,
		t.task_type_id as taskTypeId
		,p.task_type_name as taskTypeName
		,t.lookinto_date as lookintoDate
		,c.temp1,c.temp2,c.temp3,c.temp4
		from wm_task t
		left join wm_task_type p on t.task_type_id=p.id
		left join wm_task_content c on c.id=t.task_content_id
		where t.del_flag=0
		<if test="query.id!=null and query.id!=''">
			and  t.id = #{query.id}
		</if>
		<if test="query.scorePackageId!=null and query.scorePackageId!=''">
			and  t.score_package_id = #{query.scorePackageId}
		</if>
		<if test="query.taskUserId!=null and query.taskUserId!=''">
			and  t.task_user_id = #{query.taskUserId}
		</if>
		<if test="query.enableFlag!=null and query.enableFlag!=''">
			and  t.enable_flag in (${query.enableFlag})
		</if>
		order by t.create_time desc
	</select>

	<select id="getUserTaskSubScore" resultType="java.lang.Integer">
		SELECT IFNULL(sum(t.score), 0)  FROM
			wm_task t, wm_score_package p
		WHERE
			t.score_package_id = p.id
		AND p.package_type1 = '1'
		AND t.real_flag = '0'
		AND t.task_status != '4'
		AND t.task_user_id = #{userId,jdbcType=VARCHAR}
		AND (t.create_time BETWEEN #{startTime,jdbcType=TIMESTAMP} AND #{endTime,jdbcType=TIMESTAMP})
	</select>

	<select id="newGetUserTaskSubScore" resultType="java.lang.Integer">
		SELECT IFNULL(sum(t.score), 0)  FROM
			wm_task t, wm_score_package p
		WHERE
			t.score_package_id = p.id
		  AND p.package_type1 = '1'
		  AND t.real_flag = '0'
		  AND t.task_status = '3'
		  AND t.task_user_id = #{userId,jdbcType=VARCHAR}
		  AND (t.create_time BETWEEN #{startTime,jdbcType=TIMESTAMP} AND #{endTime,jdbcType=TIMESTAMP})
	</select>

	<!-- 患者教育-处方列表-分页 -->
	<select id="listTaskPrescriptionPage" resultMap="wmTaskWithContentMap">
		SELECT
		*
		FROM
		wm_task t
		LEFT JOIN wm_task_content tc ON tc.id = t.task_content_id
		<where>
			t.del_flag = 0
			AND t.real_flag = 0
			AND task_status = 3
			AND score_package_id = #{scorePackageId, jdbcType=BIGINT}
			<if test="prescriptionNo != null and prescriptionNo != ''">
				AND tc.temp3 = #{prescriptionNo, jdbcType=VARCHAR}
			</if>
		</where>
	</select>

	<!-- 患者教育-处方列表 -->
	<select id="listTaskPrescription" resultMap="wmTaskWithContentMap">
		SELECT
		*
		FROM
		wm_task t
		LEFT JOIN wm_task_content tc ON tc.id = t.task_content_id
		<where>
			t.del_flag = 0
			AND t.real_flag = 0
			AND task_status = 3
			AND score_package_id = #{scorePackageId, jdbcType=BIGINT}
			<if test="prescriptionNo != null and prescriptionNo != ''">
				AND tc.temp3 = #{prescriptionNo, jdbcType=VARCHAR}
			</if>
		</where>
	</select>

	<!-- 查询调查信息审核列表 -->
	<select id="listInfoAudit" resultMap="wmTaskMap">
		SELECT
			temp.*, u.realname AS task_user_name, u.username
		FROM
			(
				SELECT max(id) AS id, max(task_user_id) AS task_user_id, max(create_time) AS create_time,
					   max(approval_info) AS approval_info, max(plat_audit_status) AS plat_audit_status,
					   max(task_status) AS task_status, task_content_id, task_type_id
				FROM wm_task
				<where>
					del_flag = '0' AND enable_flag = '0' AND (task_type_id IN ('15', '16', '18', '30') AND task_from != '2')
					<if test="query.taskTypeId != null and query.taskTypeId != ''">
						AND task_type_id = #{query.taskTypeId, jdbcType=VARCHAR}
					</if>
					<if test="query.platAuditStatus != null and query.platAuditStatus != ''">
						AND plat_audit_status = #{query.platAuditStatus, jdbcType=VARCHAR}
					</if>
					<if test="startDate != null and endDate != null">
						AND create_time BETWEEN #{startDate, jdbcType=TIMESTAMP} AND #{endDate, jdbcType=TIMESTAMP}
					</if>
				</where>
				GROUP BY task_content_id, task_type_id
			) temp
		LEFT JOIN sys_user u ON u.user_id = temp.task_user_id
		ORDER BY temp.create_time DESC
	</select>
</mapper>
