|
|
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="com.chenhai.system.mapper.SysMedicineRecommendationMapper"> <resultMap type="SysMedicineRecommendation" id="SysMedicineRecommendationResult"> <result property="id" column="id" /> <result property="medicineName" column="medicine_name" /> <result property="medicineType" column="medicine_type" /> <result property="specification" column="specification" /> <result property="price" column="price" /> <result property="originalPrice" column="original_price" /> <result property="soldQuantity" column="sold_quantity" /> <result property="indications" column="indications" /> <result property="usageDosage" column="usage_dosage" /> <result property="precautions" column="precautions" /> <result property="storageMethod" column="storage_method" /> <result property="expiryDate" column="expiry_date" /> <result property="createdAt" column="created_at" /> <result property="updatedAt" column="updated_at" /> <result property="manufacturer" column="manufacturer" /> <result property="salesType" column="sales_type" /> <result property="expertId" column="expert_id" /> <result property="recommendReason" column="recommend_reason" /> <result property="recommendTime" column="recommend_time" /> <result property="storeName" column="store_name" /> <result property="storeAddress" column="store_address" /> <result property="storePhone" column="store_phone" /> <result property="businessHours" column="business_hours" /> <result property="storeRemark" column="store_remark" /> <result property="longitude" column="longitude" /> <result property="latitude" column="latitude" /> <result property="images" column="images" /> <result property="imageUrl" column="image_url" /> <!-- 修改这里的关联查询,使用join方式(推荐) --> <association property="expertAvatar" column="expert_id" select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertAvatarById" /> <association property="expertName" column="expert_id" select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertNameById" /> <association property="expertExpert" column="expert_id" select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertExpertById" /> <association property="expertIntroduction" column="expert_id" select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertIntroductionById" /> <association property="expertAddress" column="expert_id" select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertAddressById" /> <association property="expertExpertiseArea" column="expert_id" select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertExpertiseAreaById" /> <association property="expertWorkExperience" column="expert_id" select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertWorkExperienceById" /> </resultMap>
<!-- 或者保持原来的SELECT查询,但要修改关联查询的ID --> <select id="getExpertAvatarById" parameterType="Long" resultType="String"> SELECT avatar FROM vet_experts WHERE expert_id = #{expertId} </select>
<select id="getExpertNameById" parameterType="Long" resultType="String"> SELECT real_name FROM vet_experts WHERE expert_id = #{expertId} </select>
<select id="getExpertExpertById" parameterType="Long" resultType="String"> SELECT expert FROM vet_experts WHERE expert_id = #{expertId} </select>
<select id="getExpertIntroductionById" parameterType="Long" resultType="String"> SELECT introduction FROM vet_experts WHERE expert_id = #{expertId} </select>
<select id="getExpertAddressById" parameterType="Long" resultType="String"> SELECT address FROM vet_experts WHERE expert_id = #{expertId} </select>
<select id="getExpertExpertiseAreaById" parameterType="Long" resultType="String"> SELECT expertise_area FROM vet_experts WHERE expert_id = #{expertId} </select>
<select id="getExpertWorkExperienceById" parameterType="Long" resultType="String"> SELECT work_experience FROM vet_experts WHERE expert_id = #{expertId} </select>
<!-- 修改基础查询SQL,添加专家表关联查询(更高效的方式) --> <sql id="selectSysMedicineRecommendationVo"> select m.id, m.medicine_name, m.medicine_type, m.specification, m.price, m.original_price, m.sold_quantity, m.indications, m.usage_dosage, m.precautions, m.storage_method, m.expiry_date, m.created_at, m.updated_at, m.manufacturer, m.sales_type, m.expert_id, m.recommend_reason, m.recommend_time, m.store_name, m.store_address, m.store_phone, m.business_hours, m.store_remark, m.longitude, m.latitude, m.images, m.image_url, e.avatar as expert_avatar, e.real_name as expert_name, e.expert as expert_expert, e.introduction as expert_introduction, e.address as expert_address, e.expertise_area as expertise_area, e.work_experience as work_experience from sys_medicine_recommendation m left join vet_experts e on m.expert_id = e.expert_id left join sys_dict_data d on m.medicine_type = d.dict_value and d.dict_type = 'medicine_type' <!-- 添加字典表JOIN --> </sql>
<select id="selectSysMedicineRecommendationList" parameterType="SysMedicineRecommendation" resultMap="SysMedicineRecommendationResult"> <include refid="selectSysMedicineRecommendationVo"/> <where> <!-- 原有的条件保持不变 --> <if test="medicineName != null and medicineName != ''"> and m.medicine_name like concat('%', #{medicineName}, '%')</if> <if test="medicineType != null and medicineType != ''"> and m.medicine_type = #{medicineType}</if> <if test="specification != null and specification != ''"> and m.specification = #{specification}</if> <if test="price != null "> and m.price = #{price}</if> <if test="originalPrice != null "> and m.original_price = #{originalPrice}</if> <if test="soldQuantity != null "> and m.sold_quantity = #{soldQuantity}</if> <if test="indications != null and indications != ''"> and m.indications = #{indications}</if> <if test="usageDosage != null and usageDosage != ''"> and m.usage_dosage = #{usageDosage}</if> <if test="precautions != null and precautions != ''"> and m.precautions = #{precautions}</if> <if test="storageMethod != null and storageMethod != ''"> and m.storage_method = #{storageMethod}</if> <if test="expiryDate != null and expiryDate != ''"> and m.expiry_date = #{expiryDate}</if> <if test="createdAt != null "> and m.created_at = #{createdAt}</if> <if test="updatedAt != null "> and m.updated_at = #{updatedAt}</if> <if test="manufacturer != null and manufacturer != ''"> and m.manufacturer like concat('%', #{manufacturer}, '%')</if> <if test="salesType != null and salesType != ''"> and m.sales_type = #{salesType}</if> <if test="expertId != null "> and m.expert_id = #{expertId}</if> <if test="recommendReason != null and recommendReason != ''"> and m.recommend_reason like concat('%', #{recommendReason}, '%')</if> <if test="recommendTime != null "> and m.recommend_time = #{recommendTime}</if> <if test="storeName != null and storeName != ''"> and m.store_name like concat('%', #{storeName}, '%')</if> <if test="storeAddress != null and storeAddress != ''"> and m.store_address like concat('%', #{storeAddress}, '%')</if> <if test="images != null and images != ''"> and m.images like concat('%', #{images}, '%')</if> <if test="imageUrl != null and imageUrl != ''"> and m.image_url like concat('%', #{imageUrl}, '%')</if> <!-- 新增搜索关键词条件 --> <if test="searchKeywords != null and searchKeywords != ''"> and ( m.medicine_name like concat('%', #{searchKeywords}, '%') or m.indications like concat('%', #{searchKeywords}, '%') or m.manufacturer like concat('%', #{searchKeywords}, '%') or m.store_name like concat('%', #{searchKeywords}, '%') or m.usage_dosage like concat('%', #{searchKeywords}, '%') or e.real_name like concat('%', #{searchKeywords}, '%') or e.title like concat('%', #{searchKeywords}, '%') ) </if> </where> ORDER BY m.created_at DESC, m.id DESC </select> <select id="selectSysMedicineRecommendationById" parameterType="Long" resultMap="SysMedicineRecommendationResult"> <include refid="selectSysMedicineRecommendationVo"/> where id = #{id} </select>
<insert id="insertSysMedicineRecommendation" parameterType="SysMedicineRecommendation" useGeneratedKeys="true" keyProperty="id"> insert into sys_medicine_recommendation <trim prefix="(" suffix=")" suffixOverrides=","> <if test="medicineName != null and medicineName != ''">medicine_name,</if> <if test="medicineType != null and medicineType != ''">medicine_type,</if> <if test="specification != null and specification != ''">specification,</if> <if test="price != null">price,</if> <if test="originalPrice != null">original_price,</if> <if test="soldQuantity != null">sold_quantity,</if> <if test="indications != null and indications != ''">indications,</if> <if test="usageDosage != null and usageDosage != ''">usage_dosage,</if> <if test="precautions != null and precautions != ''">precautions,</if> <if test="storageMethod != null and storageMethod != ''">storage_method,</if> <if test="expiryDate != null and expiryDate != ''">expiry_date,</if> <if test="createdAt != null">created_at,</if> <if test="updatedAt != null">updated_at,</if> <if test="manufacturer != null and manufacturer != ''">manufacturer,</if> <if test="salesType != null and salesType != ''">sales_type,</if> <if test="expertId != null">expert_id,</if> <if test="recommendReason != null and recommendReason != ''">recommend_reason,</if> <if test="recommendTime != null">recommend_time,</if> <if test="storeName != null and storeName != ''">store_name,</if> <if test="storeAddress != null and storeAddress != ''">store_address,</if> <if test="storePhone != null and storePhone != ''">store_phone,</if> <if test="businessHours != null and businessHours != ''">business_hours,</if> <if test="storeRemark != null and storeRemark != ''">store_remark,</if> <if test="longitude != null">longitude,</if> <if test="latitude != null">latitude,</if> <if test="images != null and images != ''">images,</if> <if test="imageUrl != null and imageUrl != ''">image_url,</if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="medicineName != null and medicineName != ''">#{medicineName},</if> <if test="medicineType != null and medicineType != ''">#{medicineType},</if> <if test="specification != null and specification != ''">#{specification},</if> <if test="price != null">#{price},</if> <if test="originalPrice != null">#{originalPrice},</if> <if test="soldQuantity != null">#{soldQuantity},</if> <if test="indications != null and indications != ''">#{indications},</if> <if test="usageDosage != null and usageDosage != ''">#{usageDosage},</if> <if test="precautions != null and precautions != ''">#{precautions},</if> <if test="storageMethod != null and storageMethod != ''">#{storageMethod},</if> <if test="expiryDate != null and expiryDate != ''">#{expiryDate},</if> <if test="createdAt != null">#{createdAt},</if> <if test="updatedAt != null">#{updatedAt},</if> <if test="manufacturer != null and manufacturer != ''">#{manufacturer},</if> <if test="salesType != null and salesType != ''">#{salesType},</if> <if test="expertId != null">#{expertId},</if> <if test="recommendReason != null and recommendReason != ''">#{recommendReason},</if> <if test="recommendTime != null">#{recommendTime},</if> <if test="storeName != null and storeName != ''">#{storeName},</if> <if test="storeAddress != null and storeAddress != ''">#{storeAddress},</if> <if test="storePhone != null and storePhone != ''">#{storePhone},</if> <if test="businessHours != null and businessHours != ''">#{businessHours},</if> <if test="storeRemark != null and storeRemark != ''">#{storeRemark},</if> <if test="longitude != null">#{longitude},</if> <if test="latitude != null">#{latitude},</if> <if test="images != null and images != ''">#{images},</if> <if test="imageUrl != null and imageUrl != ''">#{imageUrl},</if> </trim> </insert>
<update id="updateSysMedicineRecommendation" parameterType="SysMedicineRecommendation"> update sys_medicine_recommendation <trim prefix="SET" suffixOverrides=","> <if test="medicineName != null and medicineName != ''">medicine_name = #{medicineName},</if> <if test="medicineType != null and medicineType != ''">medicine_type = #{medicineType},</if> <if test="specification != null and specification != ''">specification = #{specification},</if> <if test="price != null">price = #{price},</if> <if test="originalPrice != null">original_price = #{originalPrice},</if> <if test="soldQuantity != null">sold_quantity = #{soldQuantity},</if> <if test="indications != null and indications != ''">indications = #{indications},</if> <if test="usageDosage != null and usageDosage != ''">usage_dosage = #{usageDosage},</if> <if test="precautions != null and precautions != ''">precautions = #{precautions},</if> <if test="storageMethod != null and storageMethod != ''">storage_method = #{storageMethod},</if> <if test="expiryDate != null and expiryDate != ''">expiry_date = #{expiryDate},</if> <if test="createdAt != null">created_at = #{createdAt},</if> <if test="updatedAt != null">updated_at = #{updatedAt},</if> <if test="manufacturer != null and manufacturer != ''">manufacturer = #{manufacturer},</if> <if test="salesType != null and salesType != ''">sales_type = #{salesType},</if> <if test="expertId != null">expert_id = #{expertId},</if> <if test="recommendReason != null">recommend_reason = #{recommendReason},</if> <if test="recommendTime != null">recommend_time = #{recommendTime},</if> <if test="storeName != null and storeName != ''">store_name = #{storeName},</if> <if test="storeAddress != null and storeAddress != ''">store_address = #{storeAddress},</if> <if test="storePhone != null and storePhone != ''">store_phone = #{storePhone},</if> <if test="businessHours != null and businessHours != ''">business_hours = #{businessHours},</if> <if test="storeRemark != null and storeRemark != ''">store_remark = #{storeRemark},</if> <if test="longitude != null">longitude = #{longitude},</if> <if test="latitude != null">latitude = #{latitude},</if> <if test="images != null">images = #{images},</if> <if test="imageUrl != null">image_url = #{imageUrl},</if> </trim> where id = #{id} </update>
<delete id="deleteSysMedicineRecommendationById" parameterType="Long"> delete from sys_medicine_recommendation where id = #{id} </delete>
<delete id="deleteSysMedicineRecommendationByIds" parameterType="String"> delete from sys_medicine_recommendation where id in <foreach item="id" collection="array" open="(" separator="," close=")"> #{id} </foreach> </delete></mapper>
|