You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

280 lines
17 KiB

2 months ago
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="com.chenhai.system.mapper.SysMedicineRecommendationMapper">
  6. <resultMap type="SysMedicineRecommendation" id="SysMedicineRecommendationResult">
  7. <result property="id" column="id" />
  8. <result property="medicineName" column="medicine_name" />
  9. <result property="medicineType" column="medicine_type" />
  10. <result property="specification" column="specification" />
  11. <result property="price" column="price" />
  12. <result property="originalPrice" column="original_price" />
  13. <result property="soldQuantity" column="sold_quantity" />
  14. <result property="indications" column="indications" />
  15. <result property="usageDosage" column="usage_dosage" />
  16. <result property="precautions" column="precautions" />
  17. <result property="storageMethod" column="storage_method" />
  18. <result property="expiryDate" column="expiry_date" />
  19. <result property="createdAt" column="created_at" />
  20. <result property="updatedAt" column="updated_at" />
  21. <result property="manufacturer" column="manufacturer" />
  22. <result property="salesType" column="sales_type" />
  23. <result property="expertId" column="expert_id" />
  24. <result property="recommendReason" column="recommend_reason" />
  25. <result property="recommendTime" column="recommend_time" />
  26. <result property="storeName" column="store_name" />
  27. <result property="storeAddress" column="store_address" />
  28. <result property="storePhone" column="store_phone" />
  29. <result property="businessHours" column="business_hours" />
  30. <result property="storeRemark" column="store_remark" />
  31. <result property="longitude" column="longitude" />
  32. <result property="latitude" column="latitude" />
  33. <result property="images" column="images" />
  34. <result property="imageUrl" column="image_url" />
  35. <!-- 修改这里的关联查询,使用join方式(推荐) -->
  36. <association property="expertAvatar" column="expert_id"
  37. select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertAvatarById" />
  38. <association property="expertName" column="expert_id"
  39. select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertNameById" />
  40. <association property="expertExpert" column="expert_id"
  41. select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertExpertById" />
  42. <association property="expertIntroduction" column="expert_id"
  43. select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertIntroductionById" />
  44. <association property="expertAddress" column="expert_id"
  45. select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertAddressById" />
  46. <association property="expertExpertiseArea" column="expert_id"
  47. select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertExpertiseAreaById" />
  48. <association property="expertWorkExperience" column="expert_id"
  49. select="com.chenhai.system.mapper.SysMedicineRecommendationMapper.getExpertWorkExperienceById" />
  50. </resultMap>
  51. <!-- 或者保持原来的SELECT查询,但要修改关联查询的ID -->
  52. <select id="getExpertAvatarById" parameterType="Long" resultType="String">
  53. SELECT avatar FROM vet_experts WHERE expert_id = #{expertId}
  54. </select>
  55. <select id="getExpertNameById" parameterType="Long" resultType="String">
  56. SELECT real_name FROM vet_experts WHERE expert_id = #{expertId}
  57. </select>
  58. <select id="getExpertExpertById" parameterType="Long" resultType="String">
  59. SELECT expert FROM vet_experts WHERE expert_id = #{expertId}
  60. </select>
  61. <select id="getExpertIntroductionById" parameterType="Long" resultType="String">
  62. SELECT introduction FROM vet_experts WHERE expert_id = #{expertId}
  63. </select>
  64. <select id="getExpertAddressById" parameterType="Long" resultType="String">
  65. SELECT address FROM vet_experts WHERE expert_id = #{expertId}
  66. </select>
  67. <select id="getExpertExpertiseAreaById" parameterType="Long" resultType="String">
  68. SELECT expertise_area FROM vet_experts WHERE expert_id = #{expertId}
  69. </select>
  70. <select id="getExpertWorkExperienceById" parameterType="Long" resultType="String">
  71. SELECT work_experience FROM vet_experts WHERE expert_id = #{expertId}
  72. </select>
  73. <!-- 修改基础查询SQL,添加专家表关联查询(更高效的方式) -->
  74. <sql id="selectSysMedicineRecommendationVo">
  75. select
  76. m.id,
  77. m.medicine_name,
  78. m.medicine_type,
  79. m.specification,
  80. m.price,
  81. m.original_price,
  82. m.sold_quantity,
  83. m.indications,
  84. m.usage_dosage,
  85. m.precautions,
  86. m.storage_method,
  87. m.expiry_date,
  88. m.created_at,
  89. m.updated_at,
  90. m.manufacturer,
  91. m.sales_type,
  92. m.expert_id,
  93. m.recommend_reason,
  94. m.recommend_time,
  95. m.store_name,
  96. m.store_address,
  97. m.store_phone,
  98. m.business_hours,
  99. m.store_remark,
  100. m.longitude,
  101. m.latitude,
  102. m.images,
  103. m.image_url,
  104. e.avatar as expert_avatar,
  105. e.real_name as expert_name,
  106. e.expert as expert_expert,
  107. e.introduction as expert_introduction,
  108. e.address as expert_address,
  109. e.expertise_area as expertise_area,
  110. e.work_experience as work_experience
  111. from sys_medicine_recommendation m
  112. left join vet_experts e on m.expert_id = e.expert_id
  113. left join sys_dict_data d on m.medicine_type = d.dict_value
  114. and d.dict_type = 'medicine_type' <!-- 添加字典表JOIN -->
  115. </sql>
  116. <select id="selectSysMedicineRecommendationList" parameterType="SysMedicineRecommendation" resultMap="SysMedicineRecommendationResult">
  117. <include refid="selectSysMedicineRecommendationVo"/>
  118. <where>
  119. <!-- 原有的条件保持不变 -->
  120. <if test="medicineName != null and medicineName != ''"> and m.medicine_name like concat('%', #{medicineName}, '%')</if>
  121. <if test="medicineType != null and medicineType != ''"> and m.medicine_type = #{medicineType}</if>
  122. <if test="specification != null and specification != ''"> and m.specification = #{specification}</if>
  123. <if test="price != null "> and m.price = #{price}</if>
  124. <if test="originalPrice != null "> and m.original_price = #{originalPrice}</if>
  125. <if test="soldQuantity != null "> and m.sold_quantity = #{soldQuantity}</if>
  126. <if test="indications != null and indications != ''"> and m.indications = #{indications}</if>
  127. <if test="usageDosage != null and usageDosage != ''"> and m.usage_dosage = #{usageDosage}</if>
  128. <if test="precautions != null and precautions != ''"> and m.precautions = #{precautions}</if>
  129. <if test="storageMethod != null and storageMethod != ''"> and m.storage_method = #{storageMethod}</if>
  130. <if test="expiryDate != null and expiryDate != ''"> and m.expiry_date = #{expiryDate}</if>
  131. <if test="createdAt != null "> and m.created_at = #{createdAt}</if>
  132. <if test="updatedAt != null "> and m.updated_at = #{updatedAt}</if>
  133. <if test="manufacturer != null and manufacturer != ''"> and m.manufacturer like concat('%', #{manufacturer}, '%')</if>
  134. <if test="salesType != null and salesType != ''"> and m.sales_type = #{salesType}</if>
  135. <if test="expertId != null "> and m.expert_id = #{expertId}</if>
  136. <if test="recommendReason != null and recommendReason != ''"> and m.recommend_reason like concat('%', #{recommendReason}, '%')</if>
  137. <if test="recommendTime != null "> and m.recommend_time = #{recommendTime}</if>
  138. <if test="storeName != null and storeName != ''"> and m.store_name like concat('%', #{storeName}, '%')</if>
  139. <if test="storeAddress != null and storeAddress != ''"> and m.store_address like concat('%', #{storeAddress}, '%')</if>
  140. <if test="images != null and images != ''"> and m.images like concat('%', #{images}, '%')</if>
  141. <if test="imageUrl != null and imageUrl != ''"> and m.image_url like concat('%', #{imageUrl}, '%')</if>
  142. <!-- 新增搜索关键词条件 -->
  143. <if test="searchKeywords != null and searchKeywords != ''">
  144. and (
  145. m.medicine_name like concat('%', #{searchKeywords}, '%')
  146. or m.indications like concat('%', #{searchKeywords}, '%')
  147. or m.manufacturer like concat('%', #{searchKeywords}, '%')
  148. or m.store_name like concat('%', #{searchKeywords}, '%')
  149. or m.usage_dosage like concat('%', #{searchKeywords}, '%')
  150. or e.real_name like concat('%', #{searchKeywords}, '%')
  151. or e.title like concat('%', #{searchKeywords}, '%')
  152. )
  153. </if>
  154. </where>
  155. ORDER BY
  156. m.created_at DESC,
  157. m.id DESC
  158. </select>
  159. <select id="selectSysMedicineRecommendationById" parameterType="Long" resultMap="SysMedicineRecommendationResult">
  160. <include refid="selectSysMedicineRecommendationVo"/>
  161. where id = #{id}
  162. </select>
  163. <insert id="insertSysMedicineRecommendation" parameterType="SysMedicineRecommendation" useGeneratedKeys="true" keyProperty="id">
  164. insert into sys_medicine_recommendation
  165. <trim prefix="(" suffix=")" suffixOverrides=",">
  166. <if test="medicineName != null and medicineName != ''">medicine_name,</if>
  167. <if test="medicineType != null and medicineType != ''">medicine_type,</if>
  168. <if test="specification != null and specification != ''">specification,</if>
  169. <if test="price != null">price,</if>
  170. <if test="originalPrice != null">original_price,</if>
  171. <if test="soldQuantity != null">sold_quantity,</if>
  172. <if test="indications != null and indications != ''">indications,</if>
  173. <if test="usageDosage != null and usageDosage != ''">usage_dosage,</if>
  174. <if test="precautions != null and precautions != ''">precautions,</if>
  175. <if test="storageMethod != null and storageMethod != ''">storage_method,</if>
  176. <if test="expiryDate != null and expiryDate != ''">expiry_date,</if>
  177. <if test="createdAt != null">created_at,</if>
  178. <if test="updatedAt != null">updated_at,</if>
  179. <if test="manufacturer != null and manufacturer != ''">manufacturer,</if>
  180. <if test="salesType != null and salesType != ''">sales_type,</if>
  181. <if test="expertId != null">expert_id,</if>
  182. <if test="recommendReason != null and recommendReason != ''">recommend_reason,</if>
  183. <if test="recommendTime != null">recommend_time,</if>
  184. <if test="storeName != null and storeName != ''">store_name,</if>
  185. <if test="storeAddress != null and storeAddress != ''">store_address,</if>
  186. <if test="storePhone != null and storePhone != ''">store_phone,</if>
  187. <if test="businessHours != null and businessHours != ''">business_hours,</if>
  188. <if test="storeRemark != null and storeRemark != ''">store_remark,</if>
  189. <if test="longitude != null">longitude,</if>
  190. <if test="latitude != null">latitude,</if>
  191. <if test="images != null and images != ''">images,</if>
  192. <if test="imageUrl != null and imageUrl != ''">image_url,</if>
  193. </trim>
  194. <trim prefix="values (" suffix=")" suffixOverrides=",">
  195. <if test="medicineName != null and medicineName != ''">#{medicineName},</if>
  196. <if test="medicineType != null and medicineType != ''">#{medicineType},</if>
  197. <if test="specification != null and specification != ''">#{specification},</if>
  198. <if test="price != null">#{price},</if>
  199. <if test="originalPrice != null">#{originalPrice},</if>
  200. <if test="soldQuantity != null">#{soldQuantity},</if>
  201. <if test="indications != null and indications != ''">#{indications},</if>
  202. <if test="usageDosage != null and usageDosage != ''">#{usageDosage},</if>
  203. <if test="precautions != null and precautions != ''">#{precautions},</if>
  204. <if test="storageMethod != null and storageMethod != ''">#{storageMethod},</if>
  205. <if test="expiryDate != null and expiryDate != ''">#{expiryDate},</if>
  206. <if test="createdAt != null">#{createdAt},</if>
  207. <if test="updatedAt != null">#{updatedAt},</if>
  208. <if test="manufacturer != null and manufacturer != ''">#{manufacturer},</if>
  209. <if test="salesType != null and salesType != ''">#{salesType},</if>
  210. <if test="expertId != null">#{expertId},</if>
  211. <if test="recommendReason != null and recommendReason != ''">#{recommendReason},</if>
  212. <if test="recommendTime != null">#{recommendTime},</if>
  213. <if test="storeName != null and storeName != ''">#{storeName},</if>
  214. <if test="storeAddress != null and storeAddress != ''">#{storeAddress},</if>
  215. <if test="storePhone != null and storePhone != ''">#{storePhone},</if>
  216. <if test="businessHours != null and businessHours != ''">#{businessHours},</if>
  217. <if test="storeRemark != null and storeRemark != ''">#{storeRemark},</if>
  218. <if test="longitude != null">#{longitude},</if>
  219. <if test="latitude != null">#{latitude},</if>
  220. <if test="images != null and images != ''">#{images},</if>
  221. <if test="imageUrl != null and imageUrl != ''">#{imageUrl},</if>
  222. </trim>
  223. </insert>
  224. <update id="updateSysMedicineRecommendation" parameterType="SysMedicineRecommendation">
  225. update sys_medicine_recommendation
  226. <trim prefix="SET" suffixOverrides=",">
  227. <if test="medicineName != null and medicineName != ''">medicine_name = #{medicineName},</if>
  228. <if test="medicineType != null and medicineType != ''">medicine_type = #{medicineType},</if>
  229. <if test="specification != null and specification != ''">specification = #{specification},</if>
  230. <if test="price != null">price = #{price},</if>
  231. <if test="originalPrice != null">original_price = #{originalPrice},</if>
  232. <if test="soldQuantity != null">sold_quantity = #{soldQuantity},</if>
  233. <if test="indications != null and indications != ''">indications = #{indications},</if>
  234. <if test="usageDosage != null and usageDosage != ''">usage_dosage = #{usageDosage},</if>
  235. <if test="precautions != null and precautions != ''">precautions = #{precautions},</if>
  236. <if test="storageMethod != null and storageMethod != ''">storage_method = #{storageMethod},</if>
  237. <if test="expiryDate != null and expiryDate != ''">expiry_date = #{expiryDate},</if>
  238. <if test="createdAt != null">created_at = #{createdAt},</if>
  239. <if test="updatedAt != null">updated_at = #{updatedAt},</if>
  240. <if test="manufacturer != null and manufacturer != ''">manufacturer = #{manufacturer},</if>
  241. <if test="salesType != null and salesType != ''">sales_type = #{salesType},</if>
  242. <if test="expertId != null">expert_id = #{expertId},</if>
  243. <if test="recommendReason != null">recommend_reason = #{recommendReason},</if>
  244. <if test="recommendTime != null">recommend_time = #{recommendTime},</if>
  245. <if test="storeName != null and storeName != ''">store_name = #{storeName},</if>
  246. <if test="storeAddress != null and storeAddress != ''">store_address = #{storeAddress},</if>
  247. <if test="storePhone != null and storePhone != ''">store_phone = #{storePhone},</if>
  248. <if test="businessHours != null and businessHours != ''">business_hours = #{businessHours},</if>
  249. <if test="storeRemark != null and storeRemark != ''">store_remark = #{storeRemark},</if>
  250. <if test="longitude != null">longitude = #{longitude},</if>
  251. <if test="latitude != null">latitude = #{latitude},</if>
  252. <if test="images != null">images = #{images},</if>
  253. <if test="imageUrl != null">image_url = #{imageUrl},</if>
  254. </trim>
  255. where id = #{id}
  256. </update>
  257. <delete id="deleteSysMedicineRecommendationById" parameterType="Long">
  258. delete from sys_medicine_recommendation where id = #{id}
  259. </delete>
  260. <delete id="deleteSysMedicineRecommendationByIds" parameterType="String">
  261. delete from sys_medicine_recommendation where id in
  262. <foreach item="id" collection="array" open="(" separator="," close=")">
  263. #{id}
  264. </foreach>
  265. </delete>
  266. </mapper>