<?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.dayou.mapper.PersonalTargetMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.PersonalTarget">
        <result column="id" property="id" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="deleted" property="deleted" />
        <result column="personal_id" property="personalId" />
        <result column="location" property="location" />
        <result column="amount" property="amount" />
        <result column="price" property="price" />
        <result column="house_certificate" property="houseCertificate" />
        <result column="land_certificate" property="landCertificate" />
        <result column="immovable_certificate" property="immovableCertificate" />
        <result column="entity_info" property="entityInfo" />
        <result column="background_info" property="backgroundInfo" />
        <result column="selling_ability" property="sellingAbility" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        created,
        modified,
        deleted,
        personal_id, location, amount, price, house_certificate, land_certificate, immovable_certificate, entity_info, background_info, selling_ability
    </sql>

    <select id="validateProd" parameterType="java.lang.Long" resultType="com.dayou.vo.ProdValidateVO">
        SELECT
            pt.acreage,
            ROUND(pt.amount/10000,2) AS amount,
            p.location AS productionName,
            p.order_id AS productionNo ,
            CONCAT_WS('、',p.bailorA,p.bailorB) as bailor
        FROM
            personal_target pt
                LEFT JOIN personal p ON p.id = pt.personal_id
        WHERE
            pt.personal_id = #{id}
          AND pt.deleted = 0
          and p.deleted =0
    </select>

    <select id="fuzzyBackgroundList" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT
            background_info
        FROM
            personal_target
        WHERE
            background_info IS NOT NULL
          AND deleted = 0
          AND JSON_EXTRACT( background_info, '$.location' ) LIKE concat ('%',#{location},'%')
        order by id desc
    </select>
</mapper>
