| <?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.hive.dao.AllotedAndInstoredDao"> | 
|       | 
|     <resultMap type="com.matrix.system.hive.pojo.AllotedAndInstored" id="AllotedAndInstoredMap"> | 
|        <id property="iaId" column="iaId" /> | 
|        <result property="skuId" column="skuId" /> | 
|         <result property="createTime" column="create_time" /> | 
|         <result property="total" column="total" /> | 
|         <result property="priceTotal" column="priceTotal" /> | 
|          <result property="type" column="type" /> | 
|         | 
|         <result property="skuPrice" column="skuPrice" /> | 
|         <result property="goodsId" column="goodsId" /> | 
|         <result property="skuName" column="skuName" /> | 
|         <result property="goodsName" column="goodsName" /> | 
|          | 
|     </resultMap> | 
|     <!-- 分页查询 --> | 
|      | 
|     <select id="selectInPage" resultMap="AllotedAndInstoredMap"> | 
|         <if test="record.type==null or record.type=='' "> | 
|             SELECT t1.*,t3.name skuName,t3.price skuPrice,t3.id goodsId,t3.name goodsName FROM(SELECT d.INSTORE_DATE create_Time,a.INSTORE_ID iaId,a.SKU_ID skuId,a.AMOUNT total,a.PRICE_TOTAL priceTotal,1 type FROM sys_instore_detail a | 
|             LEFT JOIN sys_instore_info d ON d.ID=a.INSTORE_ID  | 
|             UNION | 
|             SELECT c.ALLOTTED_DATE createTime,b.ALLOT_ID iaId,b.SKU_ID skuId,IFNULL(-b.REAL_TOTAL,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info c ON b.ALLOT_ID =c.ID AND c.ALLOTTED_INSTORE_ID =13 | 
|             UNION | 
|             SELECT e.ALLOTTED_DATE createTime, b.ALLOT_ID iaid,b.SKU_ID skuid,IFNULL(-b.receive_total,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info e ON b.ALLOT_ID =e.ID AND e.ALLOTTED_OUTSTORE_ID =13)t1 | 
|         </if> | 
|          | 
|         <if test="record.type!=null and record.type!='' "> | 
|             SELECT t1.*,t3.name skuName,t3.price skuPrice,t3.id goodsId,t3.name goodsName FROM( | 
|             <if test="record.type==1"> | 
|             SELECT d.INSTORE_DATE create_Time,a.INSTORE_ID iaId,a.SKU_ID skuId,a.AMOUNT total,a.PRICE_TOTAL priceTotal,1 type FROM sys_instore_detail a | 
|             LEFT JOIN sys_instore_info d ON d.ID=a.INSTORE_ID  | 
|             </if> | 
|             <if test="record.type==2"> | 
|             SELECT c.ALLOTTED_DATE create_Time,b.ALLOT_ID iaId,b.SKU_ID skuId,IFNULL(-b.REAL_TOTAL,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info c ON b.ALLOT_ID =c.ID AND c.ALLOTTED_INSTORE_ID =13 | 
|             UNION | 
|             SELECT e.ALLOTTED_DATE create_Time, b.ALLOT_ID iaid,b.SKU_ID skuid,IFNULL(-b.receive_total,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info e ON b.ALLOT_ID =e.ID AND e.ALLOTTED_OUTSTORE_ID =13 | 
|             </if> | 
|             )t1 | 
|         </if> | 
|         LEFT JOIN sys_goods t3  on t1.skuid = t3.id | 
|         where 1=1 | 
|         <if test="record!=null"> | 
|               | 
|             <if test="record.startTime != null  "> | 
|                 and t1.create_Time >= #{record.startTime} | 
|             </if> | 
|             <if test="record.endTime != null "> | 
|                 and t1.create_Time <= #{record.endTime} | 
|             </if>   | 
|   | 
|             <if test="record.goodsName != null and record.goodsName!='' "> | 
|                 and t3.name like CONCAT('%',#{record.goodsName},'%')  | 
|             </if> | 
|              | 
|         </if> | 
|         <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 --> | 
|             <if test="pageVo.sort !=null  and pageVo.order !=null"> | 
|                 order by | 
|                 ${pageVo.sort} ${pageVo.order} | 
|             </if> | 
|             <if test="pageVo.offset >=0  and pageVo.limit >0"> | 
|                 limit | 
|                 #{pageVo.offset},#{pageVo.limit} | 
|             </if> | 
|         </if> | 
|     </select> | 
|      | 
|     <!-- 查询总条数 --> | 
|     <select id="selectTotalRecord"    resultType="java.lang.Integer"> | 
|        <if test="record.type==null or record.type=='' "> | 
|             SELECT count(*) FROM(SELECT d.INSTORE_DATE create_Time,a.INSTORE_ID iaId,a.SKU_ID skuId,a.AMOUNT total,a.PRICE_TOTAL priceTotal,1 type FROM sys_instore_detail a | 
|             LEFT JOIN sys_instore_info d ON d.ID=a.INSTORE_ID  | 
|             UNION | 
|             SELECT c.ALLOTTED_DATE createTime,b.ALLOT_ID iaId,b.SKU_ID skuId,IFNULL(-b.REAL_TOTAL,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info c ON b.ALLOT_ID =c.ID AND c.ALLOTTED_INSTORE_ID =13 | 
|             UNION | 
|             SELECT e.ALLOTTED_DATE createTime, b.ALLOT_ID iaid,b.SKU_ID skuid,IFNULL(-b.receive_total,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info e ON b.ALLOT_ID =e.ID AND e.ALLOTTED_OUTSTORE_ID =13)t1 | 
|         </if> | 
|          | 
|         <if test="record.type!=null and record.type!='' "> | 
|             SELECT count(*) FROM( | 
|             <if test="record.type==1"> | 
|             SELECT d.INSTORE_DATE create_Time,a.INSTORE_ID iaId,a.SKU_ID skuId,a.AMOUNT total,a.PRICE_TOTAL priceTotal,1 type FROM sys_instore_detail a | 
|             LEFT JOIN sys_instore_info d ON d.ID=a.INSTORE_ID  | 
|             </if> | 
|             <if test="record.type==2"> | 
|             SELECT c.ALLOTTED_DATE create_Time,b.ALLOT_ID iaId,b.SKU_ID skuId,IFNULL(-b.REAL_TOTAL,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info c ON b.ALLOT_ID =c.ID AND c.ALLOTTED_INSTORE_ID =13 | 
|             UNION | 
|             SELECT e.ALLOTTED_DATE create_Time, b.ALLOT_ID iaid,b.SKU_ID skuid,IFNULL(-b.receive_total,0) total,NULL priceTotal,2 type FROM sys_allot_detail b  | 
|             LEFT JOIN sys_allotted_info e ON b.ALLOT_ID =e.ID AND e.ALLOTTED_OUTSTORE_ID =13 | 
|             </if> | 
|             )t1 | 
|         </if> | 
|   | 
|         LEFT JOIN sys_goods t3  on t1.skuid = t3.id | 
|         where 1=1 | 
|         <if test="record!=null"> | 
|             <if test="record.startTime != null  "> | 
|                 and t1.create_Time >= #{record.startTime} | 
|             </if> | 
|             <if test="record.endTime != null  "> | 
|                 and t1.create_Time <= #{record.endTime} | 
|             </if>   | 
|   | 
|             <if test="record.goodsName != null and record.goodsName!='' "> | 
|                 and t3.name like CONCAT('%',#{record.goodsName},'%')  | 
|             </if> | 
|              | 
|         </if> | 
|     </select> | 
|   | 
|      | 
| </mapper> |