<?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.bonus.zlpt.company.mapper.BmCompanyInfoDao">
  <resultMap id="BaseResultMap" type="com.bonus.zlpt.company.api.domain.BmCompanyInfo">
    <!--@mbg.generated-->
    <!--@Table bm_company_info-->
    <id column="company_id" jdbcType="INTEGER" property="companyId" />
    <result column="company_name" jdbcType="VARCHAR" property="companyName" />
    <result column="company_type" jdbcType="VARCHAR" property="companyType" />
    <result column="company_ltd" jdbcType="VARCHAR" property="companyLtd" />
    <result column="credit_code" jdbcType="VARCHAR" property="creditCode" />
    <result column="register_id" jdbcType="VARCHAR" property="registerId" />
    <result column="operate_id" jdbcType="VARCHAR" property="operateId" />
    <result column="register_address" jdbcType="VARCHAR" property="registerAddress" />
    <result column="operate_address" jdbcType="VARCHAR" property="operateAddress" />
    <result column="certificateType" jdbcType="VARCHAR" property="certificatetype" />
    <result column="id_number" jdbcType="VARCHAR" property="idNumber" />
    <result column="business_license" jdbcType="VARCHAR" property="businessLicense" />
    <result column="legal_person" jdbcType="VARCHAR" property="legalPerson" />
    <result column="invitation_code" jdbcType="VARCHAR" property="invitationCode" />
    <result column="invitation_co_name" jdbcType="VARCHAR" property="invitationCoName" />
    <result column="business_scope" jdbcType="VARCHAR" property="businessScope" />
    <result column="auth_person" jdbcType="VARCHAR" property="authPerson" />
    <result column="auth_id_number" jdbcType="VARCHAR" property="authIdNumber" />
    <result column="auth_phone" jdbcType="VARCHAR" property="authPhone" />
    <result column="auth_document" jdbcType="VARCHAR" property="authDocument" />
    <result column="id_face_url" jdbcType="VARCHAR" property="idFaceUrl" />
    <result column="id_nation_url" jdbcType="VARCHAR" property="idNationUrl" />
    <result column="auth_email" jdbcType="VARCHAR" property="authEmail" />
    <result column="create_time" jdbcType="VARCHAR" property="createTime" />
    <result column="creator" jdbcType="INTEGER" property="creator" />
    <result column="auditor" jdbcType="INTEGER" property="auditor" />
    <result column="audit_time" jdbcType="VARCHAR" property="auditTime" />
    <result column="audit_remark" jdbcType="VARCHAR" property="auditRemark" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="logo_url" jdbcType="VARCHAR" property="logoUrl" />
    <result column="update_time" jdbcType="VARCHAR" property="updateTime" />
    <result column="legal_face_url" jdbcType="VARCHAR" property="legalFaceUrl" />
    <result column="legal_nation_url" jdbcType="VARCHAR" property="legalNationUrl" />
  </resultMap>

  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    company_id, company_name, company_type, company_ltd, credit_code,register_id,operate_id, register_address,
    operate_address, certificateType, id_number, business_license, legal_person, invitation_code, 
    invitation_co_name, business_scope, auth_person, auth_id_number, auth_phone, auth_document, 
    id_face_url, id_nation_url, auth_email,create_time, creator, auditor, audit_time, audit_remark,
    `status`, logo_url,update_time,legal_face_url,legal_nation_url
  </sql>

  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from bm_company_info
    where company_id = #{companyId,jdbcType=INTEGER}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    update bm_company_info set status = '4'
    where company_id = #{companyId,jdbcType=INTEGER}
  </delete>

  <insert id="insert" keyColumn="company_id" keyProperty="companyId" parameterType="com.bonus.zlpt.company.api.domain.BmCompanyInfo" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into bm_company_info (company_name, company_type, company_ltd, 
      credit_code,register_id,operate_id, register_address, operate_address,
      certificateType, id_number, business_license, 
      legal_person, invitation_code, invitation_co_name, 
      business_scope, auth_person, auth_id_number, 
      auth_phone, auth_document, id_face_url, 
      id_nation_url,auth_email, create_time, creator,
      auditor, audit_time, audit_remark, 
      `status`,logo_url update_time,legal_face_url,legal_nation_url)
    values (#{companyName,jdbcType=VARCHAR}, #{companyType,jdbcType=VARCHAR}, #{companyLtd,jdbcType=VARCHAR}, 
      #{creditCode,jdbcType=VARCHAR},#{registerId,jdbcType=VARCHAR},#{operateId,jdbcType=VARCHAR}, #{registerAddress,jdbcType=VARCHAR}, #{operateAddress,jdbcType=VARCHAR},
      #{certificatetype,jdbcType=VARCHAR}, #{idNumber,jdbcType=VARCHAR}, #{businessLicense,jdbcType=VARCHAR}, 
      #{legalPerson,jdbcType=VARCHAR}, #{invitationCode,jdbcType=VARCHAR}, #{invitationCoName,jdbcType=VARCHAR}, 
      #{businessScope,jdbcType=VARCHAR}, #{authPerson,jdbcType=VARCHAR}, #{authIdNumber,jdbcType=VARCHAR}, 
      #{authPhone,jdbcType=VARCHAR}, #{authDocument,jdbcType=VARCHAR}, #{idFaceUrl,jdbcType=VARCHAR}, 
      #{idNationUrl,jdbcType=VARCHAR},#{authEmail,jdbcType=VARCHAR}, #{createTime,jdbcType=VARCHAR}, #{creator,jdbcType=INTEGER},
      #{auditor,jdbcType=INTEGER}, #{auditTime,jdbcType=VARCHAR}, #{auditRemark,jdbcType=VARCHAR}, 
      #{status,jdbcType=VARCHAR},#{logoUrl,jdbcType=VARCHAR}, #{updateTime,jdbcType=VARCHAR},#{legalFaceUrl},#{legalNationUrl})
  </insert>

  <insert id="insertSelective" keyColumn="company_id" keyProperty="companyId" parameterType="com.bonus.zlpt.company.api.domain.BmCompanyInfo" useGeneratedKeys="true">
    <!--@mbg.generated-->
    insert into bm_company_info
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="companyName != null and companyName != ''">
        company_name,
      </if>
      <if test="companyType != null and companyType != ''">
        company_type,
      </if>
      <if test="companyLtd != null and companyLtd != ''">
        company_ltd,
      </if>
      <if test="creditCode != null and creditCode != ''">
        credit_code,
      </if>
      <if test="registerId != null and registerId != ''">
        register_id,
      </if>
      <if test="operateId != null and operateId != ''">
        operate_id,
      </if>
      <if test="registerAddress != null and registerAddress != ''">
        register_address,
      </if>
      <if test="operateAddress != null and operateAddress != ''">
        operate_address,
      </if>
      <if test="certificatetype != null and certificatetype != ''">
        certificateType,
      </if>
      <if test="idNumber != null and idNumber != ''">
        id_number,
      </if>
      <if test="businessLicense != null and businessLicense != ''">
        business_license,
      </if>
      <if test="legalPerson != null and legalPerson != ''">
        legal_person,
      </if>
      <if test="invitationCode != null and invitationCode != ''">
        invitation_code,
      </if>
      <if test="invitationCoName != null and invitationCoName != ''">
        invitation_co_name,
      </if>
      <if test="businessScope != null and businessScope != ''">
        business_scope,
      </if>
      <if test="authPerson != null and authPerson != ''">
        auth_person,
      </if>
      <if test="authIdNumber != null and authIdNumber != ''">
        auth_id_number,
      </if>
      <if test="authPhone != null and authPhone != ''">
        auth_phone,
      </if>
      <if test="authDocument != null and authDocument != ''">
        auth_document,
      </if>
      <if test="idFaceUrl != null and idFaceUrl != ''">
        id_face_url,
      </if>
      <if test="idNationUrl != null and idNationUrl != ''">
        id_nation_url,
      </if>
      <if test="authEmail != null and authEmail != ''">
        auth_email,
      </if>
      <if test="createTime != null and createTime != ''">
        create_time,
      </if>
      <if test="creator != null and creator != ''">
        creator,
      </if>
      <if test="auditor != null">
        auditor,
      </if>
      <if test="auditTime != null and auditTime != ''">
        audit_time,
      </if>
      <if test="auditRemark != null and auditRemark != ''">
        audit_remark,
      </if>
      <if test="status != null and status != ''">
        `status`,
      </if>
      <if test="logoUrl != null and logoUrl != ''">
      logo_url,
      </if>
      <if test="updateTime != null and updateTime != ''">
        update_time,
      </if>
      <if test="legalFaceUrl != null and legalFaceUrl != ''">
        legal_face_url,
      </if>
      <if test="legalNationUrl != null and legalNationUrl != ''">
        legal_nation_url,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="companyName != null and companyName != ''">
        #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="companyType != null and companyType != ''">
        #{companyType,jdbcType=VARCHAR},
      </if>
      <if test="companyLtd != null and companyLtd != ''">
        #{companyLtd,jdbcType=VARCHAR},
      </if>
      <if test="creditCode != null and creditCode != ''">
        #{creditCode,jdbcType=VARCHAR},
      </if>
      <if test="registerId != null and registerId != ''">
        #{registerId,jdbcType=VARCHAR},
      </if>
      <if test="operateId != null and operateId != ''">
        #{operateId,jdbcType=VARCHAR},
      </if>
      <if test="registerAddress != null and registerAddress != ''">
        #{registerAddress,jdbcType=VARCHAR},
      </if>
      <if test="operateAddress != null and operateAddress != ''">
        #{operateAddress,jdbcType=VARCHAR},
      </if>
      <if test="certificatetype != null and certificatetype != ''">
        #{certificatetype,jdbcType=VARCHAR},
      </if>
      <if test="idNumber != null and idNumber != ''">
        #{idNumber,jdbcType=VARCHAR},
      </if>
      <if test="businessLicense != null and businessLicense != ''">
        #{businessLicense,jdbcType=VARCHAR},
      </if>
      <if test="legalPerson != null and legalPerson != ''">
        #{legalPerson,jdbcType=VARCHAR},
      </if>
      <if test="invitationCode != null and invitationCode != ''">
        #{invitationCode,jdbcType=VARCHAR},
      </if>
      <if test="invitationCoName != null and invitationCoName != ''">
        #{invitationCoName,jdbcType=VARCHAR},
      </if>
      <if test="businessScope != null and businessScope != ''">
        #{businessScope,jdbcType=VARCHAR},
      </if>
      <if test="authPerson != null and authPerson != ''">
        #{authPerson,jdbcType=VARCHAR},
      </if>
      <if test="authIdNumber != null and authIdNumber != ''">
        #{authIdNumber,jdbcType=VARCHAR},
      </if>
      <if test="authPhone != null and authPhone != ''">
        #{authPhone,jdbcType=VARCHAR},
      </if>
      <if test="authDocument != null and authDocument != ''">
        #{authDocument,jdbcType=VARCHAR},
      </if>
      <if test="idFaceUrl != null and idFaceUrl != ''">
        #{idFaceUrl,jdbcType=VARCHAR},
      </if>
      <if test="idNationUrl != null and idNationUrl != ''">
        #{idNationUrl,jdbcType=VARCHAR},
      </if>
      <if test="authEmail != null and authEmail != ''">
        #{authEmail,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null and createTime != ''">
        #{createTime,jdbcType=VARCHAR},
      </if>
      <if test="creator != null and creator != ''">
        #{creator,jdbcType=INTEGER},
      </if>
      <if test="auditor != null">
        #{auditor,jdbcType=INTEGER},
      </if>
      <if test="auditTime != null and auditTime != ''">
        #{auditTime,jdbcType=VARCHAR},
      </if>
      <if test="auditRemark != null and auditRemark != ''">
        #{auditRemark,jdbcType=VARCHAR},
      </if>
      <if test="status != null and status != ''">
        #{status,jdbcType=VARCHAR},
      </if>
      <if test="logoUrl != null and logoUrl != ''">
      #{logoUrl,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null and updateTime != ''">
        #{updateTime,jdbcType=VARCHAR},
      </if>
      <if test="legalFaceUrl != null and legalFaceUrl != ''">
      #{legalFaceUrl},
      </if>
      <if test="legalNationUrl != null and legalNationUrl != ''">
      #{legalNationUrl},
      </if>
    </trim>
  </insert>

  <update id="updateByPrimaryKeySelective" parameterType="com.bonus.zlpt.company.api.domain.BmCompanyInfo">
    <!--@mbg.generated-->
    update bm_company_info
    <set>
      <if test="companyName != null and companyName != ''">
        company_name = #{companyName,jdbcType=VARCHAR},
      </if>
      <if test="companyType != null and companyType != ''">
        company_type = #{companyType,jdbcType=VARCHAR},
      </if>
      <if test="companyLtd != null and companyLtd != ''">
        company_ltd = #{companyLtd,jdbcType=VARCHAR},
      </if>
      <if test="creditCode != null and creditCode != ''">
        credit_code = #{creditCode,jdbcType=VARCHAR},
      </if>
      <if test="registerId != null and registerId != ''">
        register_id = #{registerId,jdbcType=VARCHAR},
      </if>
      <if test="operateId != null and operateId != ''">
        operate_id = #{operateId,jdbcType=VARCHAR},
      </if>
      <if test="registerAddress != null and registerAddress != ''">
        register_address = #{registerAddress,jdbcType=VARCHAR},
      </if>
      <if test="operateAddress != null and operateAddress != ''">
        operate_address = #{operateAddress,jdbcType=VARCHAR},
      </if>
      <if test="certificatetype != null and certificatetype != ''">
        certificateType = #{certificatetype,jdbcType=VARCHAR},
      </if>
      <if test="idNumber != null and idNumber != ''">
        id_number = #{idNumber,jdbcType=VARCHAR},
      </if>
      <if test="businessLicense != null and businessLicense != ''">
        business_license = #{businessLicense,jdbcType=VARCHAR},
      </if>
      <if test="legalPerson != null and legalPerson != ''">
        legal_person = #{legalPerson,jdbcType=VARCHAR},
      </if>
      <if test="invitationCode != null and invitationCode != ''">
        invitation_code = #{invitationCode,jdbcType=VARCHAR},
      </if>
      <if test="invitationCoName != null and invitationCoName != ''">
        invitation_co_name = #{invitationCoName,jdbcType=VARCHAR},
      </if>
      <if test="businessScope != null and businessScope != ''">
        business_scope = #{businessScope,jdbcType=VARCHAR},
      </if>
      <if test="authPerson != null and authPerson != ''">
        auth_person = #{authPerson,jdbcType=VARCHAR},
      </if>
      <if test="authIdNumber != null and authIdNumber != ''">
        auth_id_number = #{authIdNumber,jdbcType=VARCHAR},
      </if>
      <if test="authPhone != null and authPhone != ''">
        auth_phone = #{authPhone,jdbcType=VARCHAR},
      </if>
      <if test="authDocument != null and authDocument != ''">
        auth_document = #{authDocument,jdbcType=VARCHAR},
      </if>
      <if test="idFaceUrl != null and idFaceUrl != ''">
        id_face_url = #{idFaceUrl,jdbcType=VARCHAR},
      </if>
      <if test="idNationUrl != null and idNationUrl != ''">
        id_nation_url = #{idNationUrl,jdbcType=VARCHAR},
      </if>
      <if test="authEmail != null and authEmail != ''">
        auth_email = #{authEmail,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null and createTime != ''">
        create_time = #{createTime,jdbcType=VARCHAR},
      </if>
      <if test="creator != null and creator != ''">
        creator = #{creator,jdbcType=INTEGER},
      </if>
      <if test="auditor != null">
        auditor = #{auditor,jdbcType=INTEGER},
      </if>
      <if test="auditTime != null and auditTime != ''">
        audit_time = #{auditTime,jdbcType=VARCHAR},
      </if>
      <if test="auditRemark != null and auditRemark != ''">
        audit_remark = #{auditRemark,jdbcType=VARCHAR},
      </if>
      <if test="status != null and status != ''">
        `status` = #{status,jdbcType=VARCHAR},
      </if>
      <if test="logoUrl != null and logoUrl != ''">
      logo_url = #{logoUrl,jdbcType=VARCHAR},
      </if>
      <if test="updateTime != null and updateTime != ''">
        update_time = #{updateTime,jdbcType=VARCHAR},
      </if>
      <if test="legalFaceUrl != null and legalFaceUrl != ''">
        legal_face_url = #{legalFaceUrl},
      </if>
      <if test="legalNationUrl != null and legalNationUrl != ''">
        legal_nation_url = #{legalNationUrl},
      </if>
    </set>
    where company_id = #{companyId,jdbcType=INTEGER}
  </update>

  <update id="updateByPrimaryKey" parameterType="com.bonus.zlpt.company.api.domain.BmCompanyInfo">
    <!--@mbg.generated-->
    update bm_company_info
    set company_name = #{companyName,jdbcType=VARCHAR},
      company_type = #{companyType,jdbcType=VARCHAR},
      company_ltd = #{companyLtd,jdbcType=VARCHAR},
      credit_code = #{creditCode,jdbcType=VARCHAR},
    register_id = #{registerId,jdbcType=VARCHAR},
    operate_id = #{operateId,jdbcType=VARCHAR},
      register_address = #{registerAddress,jdbcType=VARCHAR},
      operate_address = #{operateAddress,jdbcType=VARCHAR},
      certificateType = #{certificatetype,jdbcType=VARCHAR},
      id_number = #{idNumber,jdbcType=VARCHAR},
      business_license = #{businessLicense,jdbcType=VARCHAR},
      legal_person = #{legalPerson,jdbcType=VARCHAR},
      invitation_code = #{invitationCode,jdbcType=VARCHAR},
      invitation_co_name = #{invitationCoName,jdbcType=VARCHAR},
      business_scope = #{businessScope,jdbcType=VARCHAR},
      auth_person = #{authPerson,jdbcType=VARCHAR},
      auth_id_number = #{authIdNumber,jdbcType=VARCHAR},
      auth_phone = #{authPhone,jdbcType=VARCHAR},
      auth_document = #{authDocument,jdbcType=VARCHAR},
      id_face_url = #{idFaceUrl,jdbcType=VARCHAR},
      id_nation_url = #{idNationUrl,jdbcType=VARCHAR},
      auth_email = #{authEmail,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=VARCHAR},
      creator = #{creator,jdbcType=INTEGER},
      auditor = #{auditor,jdbcType=INTEGER},
      audit_time = #{auditTime,jdbcType=VARCHAR},
      audit_remark = #{auditRemark,jdbcType=VARCHAR},
      `status` = #{status,jdbcType=VARCHAR},
      logo_url = #{logoUrl,jdbcType=VARCHAR},
      update_time = #{updateTime,jdbcType=VARCHAR},
    legal_face_url = #{legalFaceUrl},
    legal_nation_url = #{legalNationUrl}
    where company_id = #{companyId,jdbcType=INTEGER}
  </update>

  <select id="selectCompanyList" resultMap="BaseResultMap">
    select * from bm_company_info
    <where>
      status = '1'
      <if test="companyName!= null and companyName!= ''">
        and company_name like concat('%', #{companyName}, '%')
      </if>
      <if test="companyType!= null and companyType!= ''">
        and company_type like concat('%', #{companyType}, '%')
      </if>
    </where>
  </select>
  <select id="selectCountByCompanyType" resultType="java.lang.Integer">

    select count(*) from bm_company_info
    <where>
      status = '1'
      <if test="companyName!= null and companyName!= ''">
        and company_type = #{companyName}
      </if>
    </where>

  </select>


  <select id="selectList" resultType="com.bonus.zlpt.company.api.domain.BmCompanyInfo">
    select * from bm_company_info
    <where>
      <if test="companyName != null and companyName != ''">and company_name LIKE CONCAT('%', #{companyName}, '%')</if>
      <if test="creditCode != null and creditCode != ''">and credit_code LIKE CONCAT('%', #{creditCode}, '%')</if>
      <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
             and date_format( create_time, '%Y-%m-%d' )
        BETWEEN date_format( #{beginTime}, '%Y-%m-%d' )
        and date_format( #{endTime}, '%Y-%m-%d' )
       </if>
    <if test="userName != null and userName != ''">
      and creator in (select user_id from sys_user where user_name LIKE CONCAT('%', #{userName}, '%'))
    </if>
    </where>
  </select>
  <select id="selectUserByPhoneNumber" resultType="com.bonus.zlpt.system.api.domain.SysUser">
    select * from sys_user where phonenumber = #{phoneNumber}
  </select>
  <select id="selectCompanyInfo" resultType="com.bonus.zlpt.company.api.domain.BmCompanyInfo">
    select * from bm_company_info
    <where>
      <if test="companyName != null and companyName != ''">and company_name LIKE CONCAT('%', #{companyName}, '%')</if>
      <if test="creditCode != null and creditCode != ''">and credit_code LIKE CONCAT('%', #{creditCode}, '%')</if>
      <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
        and date_format( create_time, '%Y-%m-%d' )
        BETWEEN date_format( #{beginTime}, '%Y-%m-%d' )
        and date_format( #{endTime}, '%Y-%m-%d' )
      </if>
      <if test="userName != null and userName != ''">
        and auth_person LIKE CONCAT('%', #{userName}, '%')
      </if>
    </where>
  </select>
</mapper>