| <?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.matrix.system.shopXcx.dao.ShopInvoiceDao"> | 
|     <!-- 定义ShopInvoice 的复杂关联map --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopInvoice" id="ShopInvoiceMap"> | 
|         <id property="invoId" column="invo_id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|             <result property="userId" column="user_id" /> | 
|             <result property="orderId" column="order_id" /> | 
|             <result property="invoTitle" column="invo_title" /> | 
|             <result property="invoType" column="invo_type" /> | 
|             <result property="invoCompanyName" column="invo_company_name" /> | 
|             <result property="invoPersonalName" column="invo_personal_name" /> | 
|             <result property="invoTaxIdentifynumber" column="invo_tax_identifynumber" /> | 
|             <result property="invoContent" column="invo_content" /> | 
|             <result property="invoNature" column="invo_nature" /> | 
|             <result property="invoState" column="invo_state" /> | 
|             <result property="invoExpressCode" column="invo_express_code" /> | 
|             <result property="invoShippingAddress" column="invo_shipping_address" /> | 
|             <result property="invoShippingPerson" column="invo_shipping_person" /> | 
|             <result property="invoShippingPhone" column="invo_shipping_phone" /> | 
|             <result property="invoSendTime" column="invo_send_time" /> | 
|             <result property="orderMoney" column="order_money" /> | 
|             <result property="orderNo" column="order_no" /> | 
|             <result property="nickName" column="nick_name" /> | 
|         <result property="companyId" column="company_id" /> | 
|     </resultMap> | 
|      | 
|      | 
|     <!-- 定义ShopInvoice 的简单map  ,本map不添加其他的关联属性 --> | 
|     <resultMap type="com.matrix.system.shopXcx.bean.ShopInvoice" id="ShopInvoiceSimpleMap"> | 
|         <id property="invoId" column="invo_id" /> | 
|         <result property="createBy" column="create_by" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="updateBy" column="update_by" /> | 
|         <result property="updateTime" column="update_time" /> | 
|             <result property="userId" column="user_id" /> | 
|             <result property="orderId" column="order_id" /> | 
|             <result property="invoTitle" column="invo_title" /> | 
|             <result property="invoType" column="invo_type" /> | 
|             <result property="invoCompanyName" column="invo_company_name" /> | 
|             <result property="invoPersonalName" column="invo_personal_name" /> | 
|             <result property="invoTaxIdentifynumber" column="invo_tax_identifynumber" /> | 
|             <result property="invoContent" column="invo_content" /> | 
|             <result property="invoNature" column="invo_nature" /> | 
|             <result property="invoState" column="invo_state" /> | 
|             <result property="invoExpressCode" column="invo_express_code" /> | 
|             <result property="invoShippingAddress" column="invo_shipping_address" /> | 
|             <result property="invoShippingPerson" column="invo_shipping_person" /> | 
|             <result property="invoShippingPhone" column="invo_shipping_phone" /> | 
|             <result property="invoSendTime" column="invo_send_time" /> | 
|         <result property="companyId" column="company_id" /> | 
|     </resultMap> | 
|      | 
|     <!-- 字段sql --> | 
|     <sql id="columns"> | 
|         create_by, | 
|         create_time, | 
|         update_by, | 
|         update_time, | 
|             invo_id, | 
|             user_id, | 
|             order_id, | 
|             invo_title, | 
|             invo_type, | 
|             invo_company_name, | 
|             invo_personal_name, | 
|             invo_tax_identifynumber, | 
|             invo_content, | 
|             invo_nature, | 
|             invo_state, | 
|             invo_express_code, | 
|             invo_shipping_address, | 
|             invo_shipping_person, | 
|             invo_shipping_phone, | 
|             invo_send_time, | 
|             company_id | 
|     </sql> | 
|      | 
|     <!-- 属性sql --> | 
|     <sql id="propertys"> | 
|         #{item.createBy}, | 
|         now(), | 
|         #{item.updateBy}, | 
|         now(), | 
|             #{item.invoId}, | 
|             #{item.userId}, | 
|             #{item.orderId}, | 
|             #{item.invoTitle}, | 
|             #{item.invoType}, | 
|             #{item.invoCompanyName}, | 
|             #{item.invoPersonalName}, | 
|             #{item.invoTaxIdentifynumber}, | 
|             #{item.invoContent}, | 
|             #{item.invoNature}, | 
|             #{item.invoState}, | 
|             #{item.invoExpressCode}, | 
|             #{item.invoShippingAddress}, | 
|             #{item.invoShippingPerson}, | 
|             #{item.invoShippingPhone}, | 
|             #{item.invoSendTime}, | 
|             #{item.companyId} | 
|     </sql> | 
|      | 
|     <!-- where sql --> | 
|     <sql id="where_sql"> | 
|           | 
|          <if test="record!=null"> | 
|             <if test="(record.invoId!=null and record.invoId!='') or  (record.invoId!='' and record.invoId==0)  "> | 
|                 and invo_id  = #{record.invoId}  | 
|             </if> | 
|             <if test="(record.userId!=null and record.userId!='') or  (record.userId!='' and record.userId==0)  "> | 
|                 and user_id  = #{record.userId}  | 
|             </if> | 
|             <if test="(record.orderId!=null and record.orderId!='') or  (record.orderId!='' and record.orderId==0)  "> | 
|                 and order_id  = #{record.orderId}  | 
|             </if> | 
|             <if test="(record.invoTitle!=null and record.invoTitle!='') or  (record.invoTitle!='' and record.invoTitle==0)  "> | 
|                 and invo_title  = #{record.invoTitle}  | 
|             </if> | 
|             <if test="(record.invoType!=null and record.invoType!='') or  (record.invoType!='' and record.invoType==0)  "> | 
|                 and invo_type  = #{record.invoType}  | 
|             </if> | 
|             <if test="(record.invoCompanyName!=null and record.invoCompanyName!='') or  (record.invoCompanyName!='' and record.invoCompanyName==0)  "> | 
|                 and invo_company_name  = #{record.invoCompanyName}  | 
|             </if> | 
|             <if test="(record.invoPersonalName!=null and record.invoPersonalName!='') or  (record.invoPersonalName!='' and record.invoPersonalName==0)  "> | 
|                 and invo_personal_name  = #{record.invoPersonalName}  | 
|             </if> | 
|             <if test="(record.invoTaxIdentifynumber!=null and record.invoTaxIdentifynumber!='') or  (record.invoTaxIdentifynumber!='' and record.invoTaxIdentifynumber==0)  "> | 
|                 and invo_tax_identifynumber  = #{record.invoTaxIdentifynumber}  | 
|             </if> | 
|             <if test="(record.invoContent!=null and record.invoContent!='') or  (record.invoContent!='' and record.invoContent==0)  "> | 
|                 and invo_content  = #{record.invoContent}  | 
|             </if> | 
|             <if test="(record.invoNature!=null and record.invoNature!='') or  (record.invoNature!='' and record.invoNature==0)  "> | 
|                 and invo_nature  = #{record.invoNature}  | 
|             </if> | 
|             <if test="(record.invoState!=null and record.invoState!='') or  (record.invoState!='' and record.invoState==0)  "> | 
|                 and invo_state  = #{record.invoState}  | 
|             </if> | 
|             <if test="(record.invoExpressCode!=null and record.invoExpressCode!='') or  (record.invoExpressCode!='' and record.invoExpressCode==0)  "> | 
|                 and invo_express_code  = #{record.invoExpressCode}  | 
|             </if> | 
|             <if test="(record.invoShippingAddress!=null and record.invoShippingAddress!='') or  (record.invoShippingAddress!='' and record.invoShippingAddress==0)  "> | 
|                 and invo_shipping_address  = #{record.invoShippingAddress}  | 
|             </if> | 
|             <if test="(record.invoShippingPerson!=null and record.invoShippingPerson!='') or  (record.invoShippingPerson!='' and record.invoShippingPerson==0)  "> | 
|                 and invo_shipping_person  = #{record.invoShippingPerson}  | 
|             </if> | 
|             <if test="(record.invoShippingPhone!=null and record.invoShippingPhone!='') or  (record.invoShippingPhone!='' and record.invoShippingPhone==0)  "> | 
|                 and invo_shipping_phone  = #{record.invoShippingPhone}  | 
|             </if> | 
|             <if test="(record.invoSendTime!=null and record.invoSendTime!='') or  (record.invoSendTime!='' and record.invoSendTime==0)  "> | 
|                 and invo_send_time  = #{record.invoSendTime}  | 
|             </if> | 
|              <if test="(record.nickName!=null and record.nickName!='') or  (record.nickName!='' and record.nickName==0)  "> | 
|                  and b.nick_name like concat('%',#{record.nickName},'%') | 
|              </if> | 
|              <if test="(record.orderNo!=null and record.orderNo!='') or  (record.orderNo!='' and record.orderNo==0)  "> | 
|                  and o.order_no like concat('%', #{record.orderNo}, '%') | 
|              </if> | 
|              <if test="(record.invoiceBeginTime!=null and record.invoiceBeginTime!='')"> | 
|                  and date_format(i.create_time, '%Y-%m-%d') >= #{record.invoiceBeginTime} | 
|              </if> | 
|              <if test="(record.invoiceEndTime!=null and record.invoiceEndTime!='')"> | 
|                  and  #{record.invoiceEndTime} >= date_format(i.create_time, '%Y-%m-%d') | 
|              </if> | 
|              <if test="(record.companyId!=null and record.companyId!='') or  (record.companyId!='' and record.companyId==0)  "> | 
|                  and i.company_id  = #{record.companyId} | 
|              </if> | 
|         </if> | 
|           | 
|     </sql> | 
|      | 
|     <!--  插入方法   --> | 
|     <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopInvoice" | 
|         useGeneratedKeys="true" keyProperty="item.invoId"> | 
|         INSERT INTO shop_invoice ( | 
|              <include refid="columns"></include> | 
|         ) | 
|     VALUES ( | 
|          <include refid="propertys"></include> | 
|     ) | 
|     </insert> | 
|      | 
|      | 
|      | 
|     <!--  批量插入   --> | 
|     <insert id="batchInsert" parameterType="java.util.List"> | 
|         INSERT INTO shop_invoice ( | 
|         <include refid="columns"></include>     | 
|         ) | 
|     VALUES  | 
|     <foreach collection="list" item="item" index="index" separator=",">( | 
|         <include refid="propertys"></include>     | 
|     )</foreach> | 
|     </insert> | 
|      | 
|      | 
|      | 
|      | 
|      | 
|     <!--  根据Map更新 部分更新   --> | 
|     <update id="updateByMap" parameterType="java.util.HashMap" > | 
|         UPDATE shop_invoice | 
|         <set> | 
|             <if test="_parameter.containsKey('userId')"> | 
|                     user_id = #{userId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('orderId')"> | 
|                     order_id = #{orderId}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoTitle')"> | 
|                     invo_title = #{invoTitle}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoType')"> | 
|                     invo_type = #{invoType}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoCompanyName')"> | 
|                     invo_company_name = #{invoCompanyName}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoPersonalName')"> | 
|                     invo_personal_name = #{invoPersonalName}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoTaxIdentifynumber')"> | 
|                     invo_tax_identifynumber = #{invoTaxIdentifynumber}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoContent')"> | 
|                     invo_content = #{invoContent}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoNature')"> | 
|                     invo_nature = #{invoNature}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoState')"> | 
|                     invo_state = #{invoState}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoExpressCode')"> | 
|                     invo_express_code = #{invoExpressCode}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoShippingAddress')"> | 
|                     invo_shipping_address = #{invoShippingAddress}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoShippingPerson')"> | 
|                     invo_shipping_person = #{invoShippingPerson}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoShippingPhone')"> | 
|                     invo_shipping_phone = #{invoShippingPhone}, | 
|                 </if>         | 
|             <if test="_parameter.containsKey('invoSendTime')"> | 
|                     invo_send_time = #{invoSendTime}, | 
|                 </if>         | 
|         </set> | 
|         WHERE invo_id=#{invoId}  | 
|     </update>  | 
|      | 
|      | 
|     <!--  根据对象更新 部分更新   --> | 
|     <update id="updateByModel" parameterType="Integer"> | 
|         UPDATE shop_invoice | 
|         <set> | 
|             <if test="record.userId != null and record.userId != '' "> | 
|                 user_id  = #{record.userId},  | 
|             </if> | 
|             <if test="record.orderId != null "> | 
|                 order_id  = #{record.orderId},  | 
|             </if> | 
|             <if test="record.invoTitle != null and record.invoTitle != '' "> | 
|                 invo_title  = #{record.invoTitle},  | 
|             </if> | 
|             <if test="record.invoType != null "> | 
|                 invo_type  = #{record.invoType},  | 
|             </if> | 
|             <if test="record.invoCompanyName != null and record.invoCompanyName != '' "> | 
|                 invo_company_name  = #{record.invoCompanyName},  | 
|             </if> | 
|             <if test="record.invoPersonalName != null and record.invoPersonalName != '' "> | 
|                 invo_personal_name  = #{record.invoPersonalName},  | 
|             </if> | 
|             <if test="record.invoTaxIdentifynumber != null and record.invoTaxIdentifynumber != '' "> | 
|                 invo_tax_identifynumber  = #{record.invoTaxIdentifynumber},  | 
|             </if> | 
|             <if test="record.invoContent != null and record.invoContent != '' "> | 
|                 invo_content  = #{record.invoContent},  | 
|             </if> | 
|             <if test="record.invoNature != null "> | 
|                 invo_nature  = #{record.invoNature},  | 
|             </if> | 
|             <if test="record.invoState != null "> | 
|                 invo_state  = #{record.invoState},  | 
|             </if> | 
|             <if test="record.invoExpressCode != null and record.invoExpressCode != '' "> | 
|                 invo_express_code  = #{record.invoExpressCode},  | 
|             </if> | 
|             <if test="record.invoShippingAddress != null and record.invoShippingAddress != '' "> | 
|                 invo_shipping_address  = #{record.invoShippingAddress},  | 
|             </if> | 
|             <if test="record.invoShippingPerson != null and record.invoShippingPerson != '' "> | 
|                 invo_shipping_person  = #{record.invoShippingPerson},  | 
|             </if> | 
|             <if test="record.invoShippingPhone != null and record.invoShippingPhone != '' "> | 
|                 invo_shipping_phone  = #{record.invoShippingPhone},  | 
|             </if> | 
|             <if test="record.invoSendTime != null "> | 
|                 invo_send_time  = #{record.invoSendTime},  | 
|             </if> | 
|         </set> | 
|         WHERE invo_id=#{record.invoId}  | 
|     </update> | 
|      | 
|     <!-- 批量删除 --> | 
|     <delete id="deleteByIds" parameterType="java.util.List"> | 
|         delete from shop_invoice where  invo_id in | 
|         <foreach collection="list" index="index" item="item" open="(" | 
|             separator="," close=")"> | 
|             #{item} | 
|         </foreach> | 
|     </delete> | 
|          | 
|     <!-- 根据id删除--> | 
|     <delete id="deleteById" parameterType="Integer"> | 
|         DELETE FROM shop_invoice | 
|         where  invo_id=#{invoId}  | 
|     </delete> | 
|      | 
|     <!-- 根据对象删除--> | 
|     <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopInvoice"> | 
|         DELETE FROM shop_invoice | 
|         <where> | 
|         <include refid="where_sql" ></include> | 
|         </where> | 
|     </delete> | 
|      | 
|      | 
|      | 
|     <!-- 分页查询 --> | 
|     <select id="selectInPage" resultMap="ShopInvoiceMap"> | 
|         SELECT | 
|         i.create_by, | 
|         i.create_time, | 
|         i.update_by, | 
|         i.update_time, | 
|         i.invo_id, | 
|         i.user_id, | 
|         i.order_id, | 
|         i.invo_title, | 
|         i.invo_type, | 
|         i.invo_company_name, | 
|         i.invo_personal_name, | 
|         i.invo_tax_identifynumber, | 
|         i.invo_content, | 
|         i.invo_nature, | 
|         i.invo_state, | 
|         i.invo_express_code, | 
|         i.invo_shipping_address, | 
|         i.invo_shipping_person, | 
|         i.invo_shipping_phone, | 
|         i.invo_send_time, | 
|         o.order_no, | 
|         b.nick_name | 
|         FROM | 
|         shop_invoice i | 
|         LEFT JOIN shop_order o ON i.order_id = o.id | 
|         LEFT JOIN sys_vip_info b on i.user_id = b.id | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             order by i.create_time desc | 
|             <if test="pageVo.offset >=0  and pageVo.limit >0"> | 
|                 limit | 
|                 #{pageVo.offset},#{pageVo.limit} | 
|             </if> | 
|         </if> | 
|     </select> | 
|      | 
|     <!-- 查询总条数 --> | 
|     <select id="selectTotalRecord" parameterType="long"   resultType="java.lang.Integer"> | 
|     select count(*) | 
|         FROM | 
|         shop_invoice i | 
|         LEFT JOIN shop_order o ON i.order_id = o.id | 
|         LEFT JOIN sys_vip_info b on i.user_id = b.id | 
|         <where> | 
|            <include refid="where_sql"></include> | 
|         </where> | 
|     </select> | 
|   | 
|     <!-- 根据id查询--> | 
|     <select id="selectById" resultMap="ShopInvoiceMap"> | 
|         select  | 
|         i.create_by, | 
|         i.create_time, | 
|         i.update_by, | 
|         i.update_time, | 
|         i.invo_id, | 
|         i.user_id, | 
|         i.order_id, | 
|         i.invo_title, | 
|         i.invo_type, | 
|         i.invo_company_name, | 
|         i.invo_personal_name, | 
|         i.invo_tax_identifynumber, | 
|         i.invo_content, | 
|         i.invo_nature, | 
|         i.invo_state, | 
|         i.invo_express_code, | 
|         i.invo_shipping_address, | 
|         i.invo_shipping_person, | 
|         i.invo_shipping_phone, | 
|         i.invo_send_time, | 
|         o.order_no, | 
|         b.nick_name | 
|         FROM | 
|         shop_invoice i | 
|         LEFT JOIN shop_order o ON i.order_id = o.id | 
|         LEFT JOIN sys_vip_info b on i.user_id = b.id | 
|         where  invo_id=#{invoId}  | 
|     </select>     | 
|      | 
|      | 
|     <!-- 根据id 锁表查询--> | 
|     <select id="selectForUpdate" resultMap="ShopInvoiceMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_invoice | 
|         where  invo_id=#{invo_id}  | 
|         for update | 
|     </select>     | 
|      | 
|      | 
|      | 
|     <!-- 根据对象查询--> | 
|     <select id="selectByModel" resultMap="ShopInvoiceMap"> | 
|         select  | 
|         <include refid="columns" ></include> | 
|         from shop_invoice | 
|         <where> | 
|           <include refid="where_sql"></include> | 
|          </where> | 
|     </select> | 
|   | 
|     <!-- 根据用户id查询--> | 
|     <select id="selectByUserId" resultMap="ShopInvoiceMap"> | 
|         SELECT | 
|             i.create_by, | 
|             i.create_time, | 
|             i.update_by, | 
|             i.update_time, | 
|             i.invo_id, | 
|             i.user_id, | 
|             i.order_id, | 
|             i.invo_title, | 
|             i.invo_type, | 
|             i.invo_company_name, | 
|             i.invo_personal_name, | 
|             i.invo_tax_identifynumber, | 
|             i.invo_content, | 
|             i.invo_nature, | 
|             i.invo_state, | 
|             i.invo_express_code, | 
|             i.invo_shipping_address, | 
|             i.invo_shipping_person, | 
|             i.invo_shipping_phone, | 
|             i.invo_send_time, | 
|             o.order_money | 
|         FROM | 
|             shop_invoice i | 
|             LEFT JOIN shop_order o ON i.order_id = o.id | 
|         <where> | 
|             <if test="record!=null"> | 
|                 <if test="(record.userId!=null and record.userId!='') or  (record.userId!='' and record.userId==0)  "> | 
|                     and i.user_id = #{record.userId} | 
|                 </if> | 
|             </if> | 
|             AND o.del_flag = 2 | 
|         </where> | 
|             order by i.create_time desc | 
|         <if test="record.offset >=0  and record.limit >0"> | 
|             limit | 
|             #{record.offset},#{record.limit} | 
|         </if> | 
|     </select> | 
| </mapper> |