<?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.canteen.core.supermarket.mapper.SupermarketInfoMapper">
    <resultMap type="com.bonus.canteen.core.supermarket.domain.SupermarketInfo" id="SupermarketInfoResult">
        <result property="supermarketId"      column="supermarket_id"          />
        <result property="supermarketName"    column="supermarket_name"        />
        <result property="userId"             column="user_id"                 />
        <result property="mobile"             column="mobile"                  />
        <result property="warehouseId"        column="warehouse_id"            />
        <result property="address"            column="address"                 />
        <result property="imgUrl"             column="img_url"                 />
        <result property="ifPrintNow"         column="if_print_now"            />
        <result property="appSaleMode"        column="app_sale_mode"           />
        <result property="minDeliveryTime"    column="min_delivery_time"       />
        <result property="selectTimeInterval" column="select_time_interval"    />
        <result property="deliveryCost"       column="delivery_cost"           />
        <result property="autoVerifyDay"      column="auto_verify_day"         />
        <result property="deliveryWay"        column="delivery_way"            />
        <result property="refundLimitTime"    column="refund_limit_time"       />
        <result property="ifRelateDrp"        column="if_relate_drp"           />
        <result property="effId"              column="eff_id"                  />
        <result property="mealCode"           column="meal_code"               />
        <result property="areaId"             column="area_id"                 />
        <result property="delFlag"            column="del_flag"                />
        <result property="revision"           column="revision"                />
        <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="ifEnablePayCode"    column="if_enable_pay_code"      />
        <result property="payCodeUrl"         column="pay_code_url"            />
    </resultMap>

    <sql id="selectSupermarketInfoVo">
        select supermarket_id,supermarket_name,user_id,mobile,warehouse_id,address,img_url,if_print_now,app_sale_mode,min_delivery_time,select_time_interval,delivery_cost,auto_verify_day,delivery_way,refund_limit_time,if_relate_drp,eff_id,meal_code,area_id,del_flag,revision,create_by,create_time,update_by,update_time,if_enable_pay_code,pay_code_url from supermarket_info
    </sql>

    <select id="selectSupermarketInfoList" parameterType="com.bonus.canteen.core.supermarket.domain.SupermarketInfo" resultType="com.bonus.canteen.core.supermarket.domain.SupermarketInfo">
        select aa.area_name as areaname,whi.warehouse_name as warehousename,super.warehouse_id as warehouseid,super.supermarket_name as supermarketname,super.app_sale_mode as appsalemode
        ,super.address,super.img_url,super.mobile,super.user_id as userid,su.user_name as username,super.update_time as updatetime
        from  supermarket_info  super
        left join alloc_area aa on super.area_id=aa.area_id
        left join warehouse_info whi on super.warehouse_id=whi.warehouse_id
        left join sys_user su on super.user_id=su.user_id
        <where>
            <if test="areaId != null  and areaId != ''"> and super.area_id = #{areaId}</if>
            <if test="warehouseId != null  and warehouseId != ''"> and super.warehouse_id = #{warehouseId}</if>
        </where>
    </select>
        
    <insert id="insertSupermarketInfo" parameterType="com.bonus.canteen.core.supermarket.domain.SupermarketInfo">
        insert into supermarket_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="supermarketName    !=null and supermarketName        != '' "  >supermarket_name,     </if>
            <if test="userId             !=null and userId                 != '' "  >user_id,              </if>
            <if test="mobile             !=null and mobile                 != '' "  >mobile,               </if>
            <if test="warehouseId        !=null and warehouseId            != '' "  >warehouse_id,         </if>
            <if test="address            !=null and address                != '' "  >address,              </if>
            <if test="imgUrl 		     !=null and imgUrl 		         != '' "  >img_url,              </if>
            <if test="ifPrintNow         !=null and ifPrintNow             != '' "  >if_print_now,         </if>
            <if test="appSaleMode        !=null and appSaleMode            != '' "  >app_sale_mode,        </if>
            <if test="minDeliveryTime    !=null and minDeliveryTime        != '' "  >min_delivery_time,    </if>
            <if test="selectTimeInterval !=null and selectTimeInterval     != '' "  >select_time_interval, </if>
            <if test="deliveryCost       !=null and deliveryCost           != '' "  >delivery_cost,        </if>
            <if test="autoVerifyDay      !=null and autoVerifyDay          != '' "  >auto_verify_day,      </if>
            <if test="deliveryWay        !=null and deliveryWay            != '' "  >delivery_way,         </if>
            <if test="refundLimitTime 	 !=null and refundLimitTime 	     != '' "  >refund_limit_time,    </if>
            <if test="ifRelateDrp	     !=null and ifRelateDrp	         != '' "  >if_relate_drp,        </if>
            <if test="effId   	         !=null and effId   	             != '' "  >eff_id,               </if>
            <if test="mealCode 			 !=null and mealCode 			     != '' "  >meal_code,            </if>
            <if test="areaId   	         !=null and areaId   	             != '' "  >area_id,              </if>
            <if test="delFlag            !=null and delFlag                != '' "  >del_flag,             </if>
            <if test="revision 			 !=null and revision 			     != '' "  >revision,             </if>
            <if test="createBy           !=null and createBy               != '' "  >create_by,            </if>
            <if test="createTime	     !=null and createTime	         != '' "  >create_time,          </if>
            <if test="updateBy   	     !=null and updateBy   	         != '' "  >update_by,            </if>
            <if test="updateTime         !=null and updateTime             != '' "  >update_time,          </if>
            <if test="ifEnablePayCode    !=null and ifEnablePayCode        != '' "  >if_enable_pay_code,   </if>
            <if test="payCodeUrl  	     !=null and payCodeUrl  	         != '' "  >pay_code_url,         </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="supermarketName    !=null and supermarketName      != '' "  >#{supermarketName   },</if>
            <if test="userId             !=null and userId               != '' "  >#{userId            },</if>
            <if test="mobile             !=null and mobile               != '' "  >#{mobile            },</if>
            <if test="warehouseId        !=null and warehouseId          != '' "  >#{warehouseId       },</if>
            <if test="address            !=null and address              != '' "  >#{address           },</if>
            <if test="imgUrl 		     !=null and imgUrl 		         != '' "  >#{imgUrl 		    },</if>
            <if test="ifPrintNow         !=null and ifPrintNow           != '' "  >#{ifPrintNow        },</if>
            <if test="appSaleMode        !=null and appSaleMode          != '' "  >#{appSaleMode       },</if>
            <if test="minDeliveryTime    !=null and minDeliveryTime      != '' "  >#{minDeliveryTime   },</if>
            <if test="selectTimeInterval !=null and selectTimeInterval   != '' "  >#{selectTimeInterval},</if>
            <if test="deliveryCost       !=null and deliveryCost         != '' "  >#{deliveryCost      },</if>
            <if test="autoVerifyDay      !=null and autoVerifyDay        != '' "  >#{autoVerifyDay     },</if>
            <if test="deliveryWay        !=null and deliveryWay          != '' "  >#{deliveryWay       },</if>
            <if test="refundLimitTime 	 !=null and refundLimitTime 	 != '' "  >#{refundLimitTime 	},</if>
            <if test="ifRelateDrp	     !=null and ifRelateDrp	         != '' "  >#{ifRelateDrp	    },</if>
            <if test="effId   	         !=null and effId   	         != '' "  >#{effId   	        },</if>
            <if test="mealCode 			 !=null and mealCode 			 != '' "  >#{mealCode 			},</if>
            <if test="areaId   	         !=null and areaId   	         != '' "  >#{areaId   	        },</if>
            <if test="delFlag            !=null and delFlag              != '' "  >#{delFlag            },</if>
            <if test="revision 			 !=null and revision 			 != '' "  >#{revision 			},</if>
            <if test="createBy           !=null and createBy             != '' "  >#{createBy           },</if>
            <if test="createTime	     !=null and createTime	         != '' "  >#{createTime	        },</if>
            <if test="updateBy   	     !=null and updateBy   	         != '' "  >#{updateBy   	    },</if>
            <if test="updateTime         !=null and updateTime           != '' "  >#{updateTime         },</if>
            <if test="ifEnablePayCode    !=null and ifEnablePayCode      != '' "  >#{ifEnablePayCode    },</if>
            <if test="payCodeUrl  	     !=null and payCodeUrl  	     != '' "  >#{payCodeUrl  	    },</if>
         </trim>
    </insert>

    <update id="updateSupermarketInfo" parameterType="com.bonus.canteen.core.supermarket.domain.SupermarketInfo">
        update supermarket_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="supermarketName    !=null and supermarketName     != '' "  >supermarket_name    =#{supermarketName   },</if>
            <if test="userId             !=null and userId              != '' "  >user_id             =#{userId            },</if>
            <if test="mobile             !=null and mobile              != '' "  >mobile              =#{mobile            },</if>
            <if test="warehouseId        !=null and warehouseId         != '' "  >warehouse_id        =#{warehouseId       },</if>
            <if test="address            !=null and address             != '' "  >address             =#{address           },</if>
            <if test="imgUrl 		     !=null and imgUrl 		        != '' "  >img_url             =#{imgUrl 		    },</if>
            <if test="ifPrintNow         !=null and ifPrintNow          != '' "  >if_print_now        =#{ifPrintNow        },</if>
            <if test="appSaleMode        !=null and appSaleMode         != '' "  >app_sale_mode       =#{appSaleMode       },</if>
            <if test="minDeliveryTime    !=null and minDeliveryTime     != '' "  >min_delivery_time   =#{minDeliveryTime   },</if>
            <if test="selectTimeInterval !=null and selectTimeInterval  != '' "  >select_time_interval=#{selectTimeInterval},</if>
            <if test="deliveryCost       !=null and deliveryCost        != '' "  >delivery_cost       =#{deliveryCost      },</if>
            <if test="autoVerifyDay      !=null and autoVerifyDay       != '' "  >auto_verify_day     =#{autoVerifyDay     },</if>
            <if test="deliveryWay        !=null and deliveryWay         != '' "  >delivery_way        =#{deliveryWay       },</if>
            <if test="refundLimitTime 	 !=null and refundLimitTime 	!= '' "  >refund_limit_time   =#{refundLimitTime 	},</if>
            <if test="ifRelateDrp	     !=null and ifRelateDrp	        != '' "  >if_relate_drp       =#{ifRelateDrp	    },</if>
            <if test="effId   	         !=null and effId   	        != '' "  >eff_id              =#{effId   	        },</if>
            <if test="mealCode 			 !=null and mealCode 			!= '' "  >meal_code           =#{mealCode 			},</if>
            <if test="areaId   	         !=null and areaId   	        != '' "  >area_id             =#{areaId   	        },</if>
            <if test="delFlag            !=null and delFlag             != '' "  >del_flag            =#{delFlag           },</if>
            <if test="revision 			 !=null and revision 			!= '' "  >revision            =#{revision 			},</if>
            <if test="createBy           !=null and createBy            != '' "  >create_by           =#{createBy          },</if>
            <if test="createTime	     !=null and createTime	        != '' "  >create_time         =#{createTime	    },</if>
            <if test="updateBy   	     !=null and updateBy   	        != '' "  >update_by           =#{updateBy   	    },</if>
            <if test="updateTime         !=null and updateTime          != '' "  >update_time         =#{updateTime        },</if>
            <if test="ifEnablePayCode    !=null and ifEnablePayCode     != '' "  >if_enable_pay_code  =#{ifEnablePayCode   },</if>
            <if test="payCodeUrl  	     !=null and payCodeUrl  	    != '' "  >pay_code_url        =#{payCodeUrl  	    },</if>
        </trim>
        where supermarket_id = #{supermarketId}
    </update>

    <delete id="deleteSupermarketInfoBySupermarketId" parameterType="com.bonus.canteen.core.supermarket.domain.SupermarketInfo">
        delete from supermarket_info where supermarket_id = #{supermarketId}
    </delete>

    <delete id="deleteSupermarketInfoBySupermarketIds" parameterType="String">
        delete from supermarket_info where supermarket_id in
        <foreach item="orderId" collection="array" open="(" separator="," close=")">
            #{supermarketId}
        </foreach>
    </delete>
</mapper>