<?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.yifu.cloud.plus.v1.yifu.salary.mapper.TMinSalaryMapper">

	<resultMap id="tMinSalaryMap" type="com.yifu.cloud.plus.v1.yifu.salary.entity.TMinSalary">
		<id property="id" column="id"/>
		<result property="province" column="province"/>
		<result property="city" column="city"/>
		<result property="town" column="town"/>
		<result property="salaryBase" column="salary_base"/>
		<result property="status" column="status"/>
		<result property="startDate" column="start_date"/>
		<result property="endDate" column="end_date"/>
		<result property="createBy" column="create_user"/>
		<result property="createTime" column="CREATE_TIME"/>
	</resultMap>

	<!--tMinSalary简单分页查询-->
	<select id="getTMinSalaryPage" resultMap="tMinSalaryMap"  resultType="com.yifu.cloud.plus.v1.yifu.salary.entity.TMinSalary">
		SELECT
		id,
		province,
		city,
		town,
		salary_base,
		status,
		start_date,
		end_date,
		create_by,
		CREATE_TIME
		FROM t_min_salary
		<where>
			1=1
			<if test="tMinSalary.id != null and tMinSalary.id.trim() != ''">
				AND id = #{tMinSalary.id}
			</if>
			<if test='tMinSalary.areaFlag == null || tMinSalary.areaFlag == "1"'>
				<if test="tMinSalary.town == null">
					<if test="tMinSalary.city != null">
						AND CITY = '${tMinSalary.city}'
					</if>
					<if test="tMinSalary.city== null">
						<if test="tMinSalary.province != null">
							AND PROVINCE = '${tMinSalary.province}'
						</if>
					</if>
				</if>
				<if test="tMinSalary.town != null">
					AND TOWN = '${tMinSalary.town}'
				</if>
			</if>
			<if test='tMinSalary.areaFlag == "0"'>
				<if test="tMinSalary.province!= null  and tMinSalary.city == null">
					AND
					PROVINCE = '${tMinSalary.province}' and  CITY is null or CITY =''
				</if>
				<if test="tMinSalary.city != null and  tMinSalary.town == null">
					AND
					CITY = '${tMinSalary.city}'  and TOWN is null  or TOWN =''
				</if>
				<if test="tMinSalary.town != null ">
					AND  TOWN = '${tMinSalary.town}'
				</if>
			</if>
			<if test="tMinSalary.province != null">
				AND province = #{tMinSalary.province}
			</if>
			<if test="tMinSalary.city != null">
				AND city = #{tMinSalary.city}
			</if>
			<if test="tMinSalary.town != null">
				AND town = #{tMinSalary.town}
			</if>
			<if test="tMinSalary.salaryBase != null and tMinSalary.salaryBase.trim() != ''">
				AND salary_base = #{tMinSalary.salaryBase}
			</if>
			<if test="tMinSalary.status != null">
				AND status = #{tMinSalary.status}
			</if>
			<if test="tMinSalary.startDate != null">
				AND start_date = #{tMinSalary.startDate}
			</if>
			<if test="tMinSalary.endDate != null">
				AND end_date = #{tMinSalary.endDate}
			</if>
			<if test="tMinSalary.createBy != null and tMinSalary.createBy.trim() != ''">
				AND create_user = #{tMinSalary.createBy}
			</if>
		</where>
		ORDER  BY CREATE_TIME DESC
	</select>

	<select id="getTMinSalaryNoPage"  resultType="com.yifu.cloud.plus.v1.yifu.salary.vo.TMinSalaryExportVo">
		SELECT
		id,
		province,
		city,
		town,
		salary_base,
		status
		FROM t_min_salary
		<where>
			1=1
			<if test="tMinSalary.id != null and tMinSalary.id.trim() != ''">
				AND id = #{tMinSalary.id}
			</if>
			<if test='tMinSalary.areaFlag == null || tMinSalary.areaFlag == "1"'>
				<if test="tMinSalary.town == null">
					<if test="tMinSalary.city != null">
						AND CITY = '${tMinSalary.city}'
					</if>
					<if test="tMinSalary.city== null">
						<if test="tMinSalary.province != null">
							AND PROVINCE = '${tMinSalary.province}'
						</if>
					</if>
				</if>
				<if test="tMinSalary.town != null">
					AND TOWN = '${tMinSalary.town}'
				</if>
			</if>
			<if test='tMinSalary.areaFlag == "0"'>
				<if test="tMinSalary.province!= null  and tMinSalary.city == null">
					AND
					PROVINCE = '${tMinSalary.province}' and  CITY is null or CITY =''
				</if>
				<if test="tMinSalary.city != null and  tMinSalary.town == null">
					AND
					CITY = '${tMinSalary.city}'  and TOWN is null  or TOWN =''
				</if>
				<if test="tMinSalary.town != null ">
					AND  TOWN = '${tMinSalary.town}'
				</if>
			</if>
			<if test="tMinSalary.province != null">
				AND province = #{tMinSalary.province}
			</if>
			<if test="tMinSalary.city != null">
				AND city = #{tMinSalary.city}
			</if>
			<if test="tMinSalary.town != null">
				AND town = #{tMinSalary.town}
			</if>
			<if test="tMinSalary.salaryBase != null and tMinSalary.salaryBase.trim() != ''">
				AND salary_base = #{tMinSalary.salaryBase}
			</if>
			<if test="tMinSalary.status != null">
				AND status = #{tMinSalary.status}
			</if>
			<if test="tMinSalary.startDate != null">
				AND start_date = #{tMinSalary.startDate}
			</if>
			<if test="tMinSalary.endDate != null">
				AND end_date = #{tMinSalary.endDate}
			</if>
			<if test="tMinSalary.createBy != null and tMinSalary.createBy.trim() != ''">
				AND create_user = #{tMinSalary.createBy}
			</if>
		</where>
		ORDER  BY CREATE_TIME DESC
	</select>

	<!--tPaymentInfo数量查询-->
	<select id="selectCountTMinSalary" resultType="java.lang.Integer">
		SELECT
		count(1)
		FROM t_min_salary a
		<where>
			1=1
			<if test="tMinSalary.id != null and tMinSalary.id.trim() != ''">
				AND id = #{tMinSalary.id}
			</if>

			<if test='tMinSalary.areaFlag == null || tMinSalary.areaFlag == "1"'>
				<if test="tMinSalary.town == null">
					<if test="tMinSalary.city != null">
						AND (CITY = '${tMinSalary.city}' = '${tMinSalary.city}')
					</if>
					<if test="tMinSalary.city== null">
						<if test="tMinSalary.province != null">
							AND (PROVINCE = '${tMinSalary.province}'  = '${tMinSalary.province}')
						</if>
					</if>
				</if>
				<if test="tMinSalary.town != null ">
					AND (TOWN = '${tMinSalary.town}' = '${tMinSalary.town}')
				</if>
			</if>
			<if test='tMinSalary.areaFlag == "0"'>
				<if test="tMinSalary.province != null and tMinSalary.city == null">
					AND (
					(PROVINCE = '${tMinSalary.province}' and (a.CITY is null or a.CITY =''))
				</if>
				<if test="tMinSalary.city != null and tMinSalary.town == null">
					AND (
					(CITY = '${tMinSalary.city}'  and (TOWN is null  or TOWN =''))
				</if>
				<if test="tMinSalary.town != null ">
					AND (TOWN = '${tMinSalary.town}' or TOWN = '${tMinSalary.town}')
				</if>
			</if>
			<if test="tMinSalary.province != null">
				AND province = #{tMinSalary.province}
			</if>
			<if test="tMinSalary.city != null">
				AND city = #{tMinSalary.city}
			</if>
			<if test="tMinSalary.town != null">
				AND town = #{tMinSalary.town}
			</if>
			<if test="tMinSalary.salaryBase != null and tMinSalary.salaryBase.trim() != ''">
				AND salary_base = #{tMinSalary.salaryBase}
			</if>
			<if test="tMinSalary.status != null">
				AND status = #{tMinSalary.status}
			</if>
			<if test="tMinSalary.startDate != null">
				AND start_date = #{tMinSalary.startDate}
			</if>
			<if test="tMinSalary.endDate != null">
				AND end_date = #{tMinSalary.endDate}
			</if>
			<if test="tMinSalary.createBy != null and tMinSalary.createBy.trim() != ''">
				AND create_user = #{tMinSalary.createBy}
			</if>
		</where>
		ORDER  BY CREATE_TIME DESC
	</select>


	<select id="selectByAreaName"  resultType="Integer">
      select id from sys_area
      WHERE AREA_NAME=#{areaName}
		limit 1
	</select>

	<select id="selectByPName"  resultType="Integer">
		select count(1) from t_min_salary
		WHERE PROVINCE=#{id}
		limit 1
	</select>

	<select id="selectByTName"  resultType="Integer">
		select count(1) from t_min_salary
		WHERE CITY=#{id}
		limit 1
	</select>
	<select id="selectByCName"  resultType="Integer">
		select count(1) from t_min_salary
		WHERE TOWN=#{id}
		limit 1
	</select>

	<select id="selectId"  resultType="java.lang.Integer">
		select count(1)
		from t_min_salary
		WHERE ID=#{Id}
	</select>


	<select id="selectAddress" resultType="com.yifu.cloud.plus.v1.yifu.salary.entity.TMinSalary">
       select * from t_min_salary

	</select>
</mapper>
