<?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.goafanti.common.dao.OutsourceOrganizationMapper">
  <resultMap id="BaseResultMap" type="com.goafanti.common.model.OutsourceOrganization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="contacts" jdbcType="VARCHAR" property="contacts" />
    <result column="contacts_mobile" jdbcType="VARCHAR" property="contactsMobile" />
    <result column="province" jdbcType="INTEGER" property="province" />
    <result column="city" jdbcType="INTEGER" property="city" />
    <result column="area" jdbcType="INTEGER" property="area" />
    <result column="address" jdbcType="VARCHAR" property="address" />
    <result column="remarks" jdbcType="VARCHAR" property="remarks" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="order_no" jdbcType="VARCHAR" property="orderNo" />
    <result column="tid" jdbcType="VARCHAR" property="tid" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    id, name, contacts, contacts_mobile, province, city, area, address, remarks, create_time, 
    order_no, tid
  </sql>
  <select id="selectByExample" parameterType="com.goafanti.common.model.OutsourceOrganizationExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from outsource_organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    select 
    <include refid="Base_Column_List" />
    from outsource_organization
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    delete from outsource_organization
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.goafanti.common.model.OutsourceOrganizationExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    delete from outsource_organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.goafanti.common.model.OutsourceOrganization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    insert into outsource_organization (id, name, contacts, 
      contacts_mobile, province, city, 
      area, address, remarks, 
      create_time, order_no, tid
      )
    values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{contacts,jdbcType=VARCHAR}, 
      #{contactsMobile,jdbcType=VARCHAR}, #{province,jdbcType=INTEGER}, #{city,jdbcType=INTEGER}, 
      #{area,jdbcType=INTEGER}, #{address,jdbcType=VARCHAR}, #{remarks,jdbcType=VARCHAR}, 
      #{createTime,jdbcType=TIMESTAMP}, #{orderNo,jdbcType=VARCHAR}, #{tid,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.goafanti.common.model.OutsourceOrganization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    insert into outsource_organization
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="contacts != null">
        contacts,
      </if>
      <if test="contactsMobile != null">
        contacts_mobile,
      </if>
      <if test="province != null">
        province,
      </if>
      <if test="city != null">
        city,
      </if>
      <if test="area != null">
        area,
      </if>
      <if test="address != null">
        address,
      </if>
      <if test="remarks != null">
        remarks,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="tid != null">
        tid,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="contacts != null">
        #{contacts,jdbcType=VARCHAR},
      </if>
      <if test="contactsMobile != null">
        #{contactsMobile,jdbcType=VARCHAR},
      </if>
      <if test="province != null">
        #{province,jdbcType=INTEGER},
      </if>
      <if test="city != null">
        #{city,jdbcType=INTEGER},
      </if>
      <if test="area != null">
        #{area,jdbcType=INTEGER},
      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="tid != null">
        #{tid,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.goafanti.common.model.OutsourceOrganizationExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    select count(*) from outsource_organization
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    update outsource_organization
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.name != null">
        name = #{record.name,jdbcType=VARCHAR},
      </if>
      <if test="record.contacts != null">
        contacts = #{record.contacts,jdbcType=VARCHAR},
      </if>
      <if test="record.contactsMobile != null">
        contacts_mobile = #{record.contactsMobile,jdbcType=VARCHAR},
      </if>
      <if test="record.province != null">
        province = #{record.province,jdbcType=INTEGER},
      </if>
      <if test="record.city != null">
        city = #{record.city,jdbcType=INTEGER},
      </if>
      <if test="record.area != null">
        area = #{record.area,jdbcType=INTEGER},
      </if>
      <if test="record.address != null">
        address = #{record.address,jdbcType=VARCHAR},
      </if>
      <if test="record.remarks != null">
        remarks = #{record.remarks,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.orderNo != null">
        order_no = #{record.orderNo,jdbcType=VARCHAR},
      </if>
      <if test="record.tid != null">
        tid = #{record.tid,jdbcType=VARCHAR},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    update outsource_organization
    set id = #{record.id,jdbcType=INTEGER},
      name = #{record.name,jdbcType=VARCHAR},
      contacts = #{record.contacts,jdbcType=VARCHAR},
      contacts_mobile = #{record.contactsMobile,jdbcType=VARCHAR},
      province = #{record.province,jdbcType=INTEGER},
      city = #{record.city,jdbcType=INTEGER},
      area = #{record.area,jdbcType=INTEGER},
      address = #{record.address,jdbcType=VARCHAR},
      remarks = #{record.remarks,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      order_no = #{record.orderNo,jdbcType=VARCHAR},
      tid = #{record.tid,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.goafanti.common.model.OutsourceOrganization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    update outsource_organization
    <set>
      <if test="name != null">
        name = #{name,jdbcType=VARCHAR},
      </if>
      <if test="contacts != null">
        contacts = #{contacts,jdbcType=VARCHAR},
      </if>
      <if test="contactsMobile != null">
        contacts_mobile = #{contactsMobile,jdbcType=VARCHAR},
      </if>
      <if test="province != null">
        province = #{province,jdbcType=INTEGER},
      </if>
      <if test="city != null">
        city = #{city,jdbcType=INTEGER},
      </if>
      <if test="area != null">
        area = #{area,jdbcType=INTEGER},
      </if>
      <if test="address != null">
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="remarks != null">
        remarks = #{remarks,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=VARCHAR},
      </if>
      <if test="tid != null">
        tid = #{tid,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.goafanti.common.model.OutsourceOrganization">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jun 21 10:02:00 CST 2019.
    -->
    update outsource_organization
    set name = #{name,jdbcType=VARCHAR},
      contacts = #{contacts,jdbcType=VARCHAR},
      contacts_mobile = #{contactsMobile,jdbcType=VARCHAR},
      province = #{province,jdbcType=INTEGER},
      city = #{city,jdbcType=INTEGER},
      area = #{area,jdbcType=INTEGER},
      address = #{address,jdbcType=VARCHAR},
      remarks = #{remarks,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      order_no = #{orderNo,jdbcType=VARCHAR},
      tid = #{tid,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <select id="selectOutsourceOrg" resultType="com.goafanti.order.bo.OutsourceOrganizationBo">
  select id, name, contacts, contacts_mobile as contactsMobile, province, city, area, address, remarks, create_time as createTime,
  	date_format(create_time,'%Y-%m-%d %H:%i:%S') as createTimes, order_no as orderNo from outsource_organization
  	where 1=1
  	and tid= #{tid}
  	<if test="orderNo != null">
    and  order_no= #{orderNo}
  	</if>
  </select>
  <select id="selectOrderOutsourceOrg" resultType="com.goafanti.order.bo.OutsourceOrganizationBo">
  select a.order_no as orderNo,a.contract_no as contractNo,b.commodity_name as tname,b.project_status as projectStatus,
	c.id,c.name,c.province,c.city,c.area,c.address,c.contacts,date_format(c.create_time,'%Y-%m-%d %H:%I:%S') as createTimes,
	c.contacts_mobile as contactsMobile,c.remarks from t_order_new a 
	left join t_order_task b on a.order_no=b.order_no left join outsource_organization c on b.id=c.tid
	where a.delete_sign=0 and b.status=0 and c.id is not null
	and a.order_no= #{orderNo}
  </select>
</mapper>