<?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.qs.serve.modules.tbs.mapper.TbsCostApplyMapper" >
<resultMap id= "tbsCostApplyMap" type= "com.qs.serve.modules.tbs.entity.TbsCostApply" >
<result property= "id" column= "id" />
<result property= "code" column= "code" />
<result property= "chargeTheme" column= "charge_theme" />
<result property= "supplierId" column= "supplier_id" />
<result property= "supplierCode" column= "supplier_code" />
<result property= "supplierName" column= "supplier_name" />
<result property= "chargeState" column= "charge_state" />
<result property= "submitTime" column= "submit_time" />
<result property= "passTime" column= "pass_time" />
<result property= "remark" column= "remark" />
<result property= "userId" column= "user_id" />
<result property= "userCode" column= "user_code" />
<result property= "userName" column= "user_name" />
<result property= "syFormId" column= "sy_form_id" />
<result property= "syFlowId" column= "sy_flow_id" />
<result property= "totalActivity" column= "total_activity" />
<result property= "totalActivityAmount" column= "total_activity_amount" />
<result property= "totalActivityUsedAmount" column= "total_activity_used_amount" />
<result property= "contractFlag" column= "contract_flag" />
<result property= "createTime" column= "create_time" />
<result property= "updateTime" column= "update_time" />
<result property= "tenantId" column= "tenant_id" />
<result property= "createBy" column= "create_by" />
<result property= "updateBy" column= "update_by" />
<result property= "delFlag" column= "del_flag" />
<result property= "templateId" column= "template_id" />
<result property= "actEndDate" column= "act_end_date" />
<result property= "cancelFlag" column= "cancel_flag" />
<result property= "changeExtendId" column= "change_extend_id" />
<result property= "changeSourceId" column= "change_source_id" />
<result property= "supplierBizRegionFirstName" column= "supplier_biz_region_first_name" />
<result property= "supplierBizRegionSecondName" column= "supplier_biz_region_second_name" />
<result property= "supplierBizRegionThirdName" column= "supplier_biz_region_third_name" />
</resultMap>
<sql id= "tbsCostApplySql" >
tbs_cost_apply.`id`,
tbs_cost_apply.`code`,
tbs_cost_apply.`charge_theme`,
tbs_cost_apply.`supplier_id`,
tbs_cost_apply.`supplier_code`,
tbs_cost_apply.`supplier_name`,
tbs_cost_apply.`supplier_biz_region_first_name`,
tbs_cost_apply.`supplier_biz_region_second_name`,
tbs_cost_apply.`supplier_biz_region_third_name`,
tbs_cost_apply.`charge_state`,
tbs_cost_apply.`check_state`,
tbs_cost_apply.`submit_time`,
tbs_cost_apply.`pass_time`,
tbs_cost_apply.`remark`,
tbs_cost_apply.`user_id`,
tbs_cost_apply.`user_code`,
tbs_cost_apply.`user_name`,
tbs_cost_apply.`sy_form_id`,
tbs_cost_apply.`sy_flow_id`,
tbs_cost_apply.`total_activity`,
tbs_cost_apply.`total_activity_amount`,
tbs_cost_apply.`total_activity_used_amount`,
tbs_cost_apply.`contract_flag`,
tbs_cost_apply.`create_time`,
tbs_cost_apply.`update_time`,
tbs_cost_apply.`tenant_id`,
tbs_cost_apply.`create_by`,
tbs_cost_apply.`update_by`,
tbs_cost_apply.`del_flag`,
tbs_cost_apply.`template_id`,
tbs_cost_apply.`change_source_id`,
tbs_cost_apply.`change_extend_id`,
tbs_cost_apply.`cancel_flag`,
tbs_cost_apply.`template_title` </sql>
<select id= "selectCostApplyList" parameterType= "com.qs.serve.modules.tbs.entity.TbsCostApply" resultMap= "tbsCostApplyMap" >
SELECT
<if test= "query!=null" >
<if test= "query.overdueState!=null" >
`tbs_activity`.`pre_check_date` act_end_date,
</if>
</if>
<include refid= "tbsCostApplySql" />
FROM `tbs_cost_apply` `tbs_cost_apply`
<if test= "query!=null" >
<if test= "query.overdueState!=null" >
left JOIN `tbs_activity` on `tbs_cost_apply`.id = `tbs_activity`.cost_apply_id
</if>
</if>
WHERE `tbs_cost_apply`.`del_flag` = 0
<if test= "query!=null" >
<if test= "query.overdueState!=null and query.overdueState==0" >
and `tbs_activity`.`del_flag` = 0
and `tbs_activity`.`activity_state` != 2
and `tbs_cost_apply`.`charge_state` = 2
and `tbs_activity`.pre_check_date > = #{query.nowDate}
</if>
<if test= "query.overdueState!=null and query.overdueState==1" >
and `tbs_activity`.`del_flag` = 0
and `tbs_activity`.`activity_state` != 2
and `tbs_cost_apply`.`charge_state` = 2
and `tbs_activity`.pre_check_date < #{query.nowDate}
</if>
<if test= "query.overdueState!=null and query.overdueState==2" >
and `tbs_activity`.`del_flag` = 0
and `tbs_activity`.`activity_state` != 2
and `tbs_cost_apply`.`charge_state` = 2
and `tbs_activity`.pre_check_date > = #{query.startNowDate}
and `tbs_activity`.pre_check_date < = #{query.nowDate}
</if>
<include refid= "baseWhere4CostApply" />
</if>
<if test= "query.selectUserIds!=null and query.selectUserIds.size > 0" >
and ( `tbs_cost_apply`.`user_id` in
<foreach collection= "query.selectUserIds" item= "selectId" index= "i" open= "(" close= ")" separator= "," >
#{selectId}
</foreach>
or `tbs_cost_apply`.`ext_user_id` in
<foreach collection= "query.selectUserIds" item= "selectId" index= "i" open= "(" close= ")" separator= "," >
#{selectId}
</foreach> )
</if>
order by tbs_cost_apply.`create_time` DESC
</select>
<select id= "selectCountOverdueState" resultType= "java.lang.Long" >
SELECT
count(*)
FROM `tbs_cost_apply` `tbs_cost_apply`
left JOIN `tbs_activity`
on `tbs_cost_apply`.id = `tbs_activity`.cost_apply_id
WHERE
`tbs_cost_apply`.`del_flag` = 0
and `tbs_activity`.`del_flag` = 0
and `tbs_activity`.`activity_state` = 0
and `tbs_cost_apply`.`charge_state` = 2
and `tbs_activity`.pre_check_date > = #{startNowDate}
and `tbs_activity`.pre_check_date < #{nowDate}
and `tbs_cost_apply`.`user_id` = #{userId}
</select>
<sql id= "baseWhere4CostApply" >
<if test= "query.checkState != null" > and `tbs_cost_apply`.`check_state` = #{query.checkState}</if>
<if test= "query.id != null" > and `tbs_cost_apply`.`id` = #{query.id}</if>
<if test= "query.code != null and query.code != ''" > and `tbs_cost_apply`.`code` like concat('%', #{query.code},'%')</if>
<if test= "query.chargeTheme != null and query.chargeTheme != ''" > and `tbs_cost_apply`.`charge_theme` like concat('%', #{query.chargeTheme},'%')</if>
<if test= "query.supplierId != null" > and `tbs_cost_apply`.`supplier_id` = #{query.supplierId}</if>
<if test= "query.supplierCode != null and query.supplierCode != ''" > and `tbs_cost_apply`.`supplier_code` like concat('%', #{query.supplierCode},'%') </if>
<if test= "query.supplierName != null and query.supplierName != ''" > and `tbs_cost_apply`.`supplier_name` like concat('%', #{query.supplierName},'%') </if>
<if test= "query.supplierBizRegionFirstName != null and query.supplierBizRegionFirstName != ''" > and `tbs_cost_apply`.`supplier_biz_region_first_name` like concat('%', #{query.supplierBizRegionFirstName},'%') </if>
<if test= "query.supplierBizRegionSecondName != null and query.supplierBizRegionSecondName != ''" > and `tbs_cost_apply`.`supplier_biz_region_second_name` like concat('%', #{query.supplierBizRegionSecondName},'%') </if>
<if test= "query.supplierBizRegionThirdName != null and query.supplierBizRegionThirdName != ''" > and `tbs_cost_apply`.`supplier_biz_region_third_name` like concat('%', #{query.supplierBizRegionThirdName},'%') </if>
<if test= "query.chargeState != null" > and `tbs_cost_apply`.`charge_state` = #{query.chargeState}</if>
<if test= "query.submitTime != null" > and `tbs_cost_apply`.`submit_time` = #{query.submitTime}</if>
<if test= "query.passTime != null" > and `tbs_cost_apply`.`pass_time` = #{query.passTime}</if>
<if test= "query.userId != null and query.userId != ''" > and `tbs_cost_apply`.`user_id` = #{query.userId}</if>
<if test= "query.userCode != null and query.userCode != ''" > and `tbs_cost_apply`.`user_code` = #{query.userCode}</if>
<if test= "query.userName != null and query.userName != ''" > and `tbs_cost_apply`.`user_name` like concat('%', #{query.userName},'%')</if>
<if test= "query.syFormId != null and query.syFormId != ''" > and `tbs_cost_apply`.`sy_form_id` = #{query.syFormId}</if>
<if test= "query.syFlowId != null and query.syFlowId != ''" > and `tbs_cost_apply`.`sy_flow_id` = #{query.syFlowId}</if>
<if test= "query.totalActivity != null" > and `tbs_cost_apply`.`total_activity` = #{query.totalActivity}</if>
<if test= "query.totalActivityAmount != null" > and `tbs_cost_apply`.`total_activity_amount` = #{query.totalActivityAmount}</if>
<if test= "query.totalActivityUsedAmount != null" > and `tbs_cost_apply`.`total_activity_used_amount` = #{query.totalActivityUsedAmount}</if>
<if test= "query.contractFlag != null" > and `tbs_cost_apply`.`contract_flag` = #{query.contractFlag}</if>
<if test= "query.createTime != null" > and `tbs_cost_apply`.`create_time` = #{query.createTime}</if>
<if test= "query.updateTime != null" > and `tbs_cost_apply`.`update_time` = #{query.updateTime}</if>
<if test= "query.tenantId != null and query.tenantId != ''" > and `tbs_cost_apply`.`tenant_id` = #{query.tenantId}</if>
<if test= "query.createBy != null and query.createBy != ''" > and `tbs_cost_apply`.`create_by` = #{query.createBy}</if>
<if test= "query.updateBy != null and query.updateBy != ''" > and `tbs_cost_apply`.`update_by` = #{query.updateBy}</if>
<if test= "query.delFlag != null and query.delFlag != ''" > and `tbs_cost_apply`.`del_flag` = #{query.delFlag}</if>
<if test= "query.templateTitle != null and query.templateTitle != ''" > and `tbs_cost_apply`.`template_title` like concat('%', #{query.templateTitle},'%')</if>
</sql>
</mapper>