SparePartInfoMapper.xml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.platform.dao.mapper.sqarepartmanage.SparePartInfoMapper">
  4. <resultMap id="BaseResultMap" type="com.platform.dao.entity.sqarepartmanage.SparePartInfo">
  5. <id column="id" jdbcType="VARCHAR" property="id"/>
  6. <result column="unite_no" jdbcType="VARCHAR" property="uniteNo"/>
  7. <result column="no" jdbcType="VARCHAR" property="no"/>
  8. <result column="init_no" jdbcType="VARCHAR" property="initNo"/>
  9. <result column="name_no" jdbcType="VARCHAR" property="nameNo"/>
  10. <result column="gg_no" jdbcType="VARCHAR" property="ggNo"/>
  11. <result column="name" jdbcType="VARCHAR" property="name"/>
  12. <result column="type_id" jdbcType="VARCHAR" property="typeId"/>
  13. <result column="parent_type_id" jdbcType="VARCHAR" property="parentTypeId"/>
  14. <result column="middle_type_id" jdbcType="VARCHAR" property="middleTypeId"/>
  15. <result column="child_type_id" jdbcType="VARCHAR" property="childTypeId"/>
  16. <result column="parent_no" jdbcType="VARCHAR" property="parentNo"/>
  17. <result column="middle_no" jdbcType="VARCHAR" property="middleNo"/>
  18. <result column="child_no" jdbcType="VARCHAR" property="childNo"/>
  19. <result column="image" jdbcType="VARCHAR" property="image"/>
  20. <result column="qr_code" jdbcType="VARCHAR" property="qrCode"/>
  21. <result column="level" jdbcType="SMALLINT" property="level"/>
  22. <result column="initial_value" jdbcType="DOUBLE" property="initialValue"/>
  23. <result column="producer_id" jdbcType="VARCHAR" property="producerId"/>
  24. <result column="supplier_id" jdbcType="VARCHAR" property="supplierId"/>
  25. <result column="unit" jdbcType="SMALLINT" property="unit"/>
  26. <result column="warn_status" jdbcType="SMALLINT" property="warnStatus"/>
  27. <result column="forecast_status" jdbcType="SMALLINT" property="forecastStatus"/>
  28. <result column="unit_bz" jdbcType="SMALLINT" property="unitBz"/>
  29. <result column="unit_rate" jdbcType="DOUBLE" property="unitRate"/>
  30. <result column="max_stock" jdbcType="DOUBLE" property="maxStock"/>
  31. <result column="min_stock" jdbcType="DOUBLE" property="minStock"/>
  32. <result column="init_stock" jdbcType="DOUBLE" property="initStock"/>
  33. <result column="zbh" jdbcType="VARCHAR" property="zbh"/>
  34. <result column="ggxh" jdbcType="VARCHAR" property="ggxh"/>
  35. <result column="english_name" jdbcType="VARCHAR" property="englishName"/>
  36. <result column="zjm" jdbcType="VARCHAR" property="zjm"/>
  37. <result column="cd" jdbcType="INTEGER" property="cd"/>
  38. <result column="yt" jdbcType="INTEGER" property="yt"/>
  39. <result column="purchase_period" jdbcType="DECIMAL" property="purchasePeriod"/>
  40. <result column="age_period" jdbcType="DECIMAL" property="agePeriod"/>
  41. <result column="use_period" jdbcType="DECIMAL" property="usePeriod"/>
  42. <result column="params" jdbcType="VARCHAR" property="params"/>
  43. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  44. <result column="created_user_id" jdbcType="VARCHAR" property="createdUserId"/>
  45. <result column="update_user_id" jdbcType="VARCHAR" property="updateUserId"/>
  46. <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
  47. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  48. <association column="type_id" javaType="string" property="typeName"
  49. select="com.platform.dao.mapper.sqarepartmanage.SpareTypeMapper.selectNameById"/>
  50. <association column="producer_id" javaType="string" property="producerName"
  51. select="com.platform.dao.mapper.firm.FirmProducerMapper.selectNameById"/>
  52. <association column="supplier_id" javaType="string" property="supplierName"
  53. select="com.platform.dao.mapper.purchase.SupplierMapper.selectNameById"/>
  54. </resultMap>
  55. <sql id="Base_Column_List">
  56. id, no, unite_no, gg_no, name_no, name, type_id, level, initial_value, producer_id,
  57. unit,
  58. purchase_period,
  59. use_period,age_period,
  60. unit_bz,
  61. warn_status,forecast_status,
  62. unit_rate,
  63. image,
  64. qr_code,
  65. max_stock, min_stock,init_stock,supplier_id,
  66. remark, created_user_id, update_user_id, created_time, update_time,
  67. zbh,init_no,
  68. parent_type_id,
  69. child_type_id,
  70. middle_type_id,
  71. child_no,
  72. parent_no,
  73. middle_no,
  74. ggxh,
  75. english_name,
  76. zjm,
  77. cd,
  78. yt
  79. </sql>
  80. <select id="selectPageList" parameterType="com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO"
  81. resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  82. select info.*, SUM(spareStore.num) currentStock
  83. from t_spare_part_info info
  84. LEFT JOIN t_spare_store spareStore on spareStore.spare_id = info.id
  85. <if test="producerName != null and producerName != ''">
  86. LEFT JOIN t_firm_producer producer on producer.id = info.producer_id
  87. </if>
  88. <if test="supplierName != null and supplierName != ''">
  89. LEFT JOIN t_supplier supplier on supplier.id = info.supplier_id
  90. </if>
  91. <where>
  92. <if test="warnStatusList != null and warnStatusList.size > 0">
  93. AND info.warn_status in
  94. <foreach item="item" index="index" collection="warnStatusList" open="(" close=")" separator=",">
  95. #{item}
  96. </foreach>
  97. </if>
  98. <if test="forecastStatusList != null and forecastStatusList.size > 0">
  99. AND info.forecast_status in
  100. <foreach item="item" index="index" collection="forecastStatusList" open="(" close=")" separator=",">
  101. #{item}
  102. </foreach>
  103. </if>
  104. <if test="typeId != null and typeId != ''">
  105. and info.type_id = #{typeId}
  106. </if>
  107. <if test="producerName != null and producerName != ''">
  108. AND producer.name like concat('%',#{producerName},'%')
  109. </if>
  110. <if test="supplierName != null and supplierName != ''">
  111. AND supplier.name like concat('%',#{supplierName},'%')
  112. </if>
  113. <if test="keyword != null and keyword != ''">
  114. AND ( info.name like concat('%',#{keyword},'%') or
  115. info.no like concat('%',#{keyword},'%'))
  116. </if>
  117. <if test="name != null and name != ''">
  118. AND info.name = #{name}
  119. </if>
  120. <if test="warnStatus != null and warnStatus != ''">
  121. AND info.warn_status = #{warnStatus}
  122. </if>
  123. <if test="forecastStatus != null and forecastStatus != ''">
  124. AND info.forecast_status = #{forecastStatus}
  125. </if>
  126. <if test="ggxh != null and ggxh != ''">
  127. AND info.ggxh like concat('%',#{ggxh},'%')
  128. </if>
  129. <if test="initNo != null and initNo != ''">
  130. AND info.init_no like concat('%',#{initNo},'%')
  131. </if>
  132. <if test="yt != null">
  133. AND info.yt=#{yt}
  134. </if>
  135. <if test="storeId != null and storeId != ''">
  136. AND spare.store_id=#{storeId}
  137. </if>
  138. <if test="level != null and level != ''">
  139. AND info.level=#{level}
  140. </if>
  141. <if test="typeIds != null and typeIds.size > 0">
  142. AND info.type_id in
  143. <foreach item="item" index="index" collection="typeIds" open="(" close=")" separator=",">
  144. #{item}
  145. </foreach>
  146. </if>
  147. <if test="producerId != null and producerId != ''">
  148. AND info.producer_id=#{producerId}
  149. </if>
  150. <if test="supplierId != null and producerId != ''">
  151. AND info.supplier_id=#{supplierId}
  152. </if>
  153. <if test="parentTypeId != null and parentTypeId != ''">
  154. AND info.parent_type_id=#{parentTypeId}
  155. </if>
  156. <!-- <if test="typeId != null and typeId != ''">
  157. AND info.type_id=#{typeId}
  158. </if>-->
  159. <if test="parentNo != null and parentNo != ''">
  160. AND info.parent_no=#{parentNo}
  161. </if>
  162. <if test="childNo != null and childNo != ''">
  163. AND info.child_no=#{childNo}
  164. </if>
  165. <if test="searchMinStockWarn">
  166. AND info.min_stock is not null
  167. </if>
  168. <if test="searchMinStockWarn">
  169. AND info.warn_status = 0
  170. </if>
  171. </where>
  172. group by info.id
  173. <if test="searchMinStockWarn">
  174. HAVING info.min_stock > SUM( spareStore.num )
  175. </if>
  176. </select>
  177. <select id="selectMaxNo" parameterType="java.lang.Object" resultType="java.lang.String">
  178. select max(no) from t_spare_part_info
  179. where type_id = #{value}
  180. </select>
  181. <select id="selectById" parameterType="java.lang.Object" resultMap="BaseResultMap">
  182. select
  183. <include refid="Base_Column_List"/>
  184. from t_spare_part_info
  185. where id = #{value}
  186. </select>
  187. <select id="selectNameById" parameterType="java.lang.Object" resultType="java.lang.String">
  188. select name
  189. from t_spare_part_info
  190. where id = #{value}
  191. </select>
  192. <select id="selectSpareInfoList" resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  193. select spare.id as spareId, spare.no, spare.unite_no, spare.name, spare.type_id, spare.level,
  194. spare.initial_value, spare.producer_id,
  195. spare.unit,
  196. spare.unit_bz,spare.warn_status, spare.forecast_status,
  197. spare.unit_rate,
  198. spare.image,
  199. spare.qr_code,
  200. spare.zbh,spare.init_no,
  201. spare.gg_no, spare.name_no,
  202. spare.ggxh,
  203. spare.english_name,
  204. spare.zjm,
  205. spare.cd,
  206. spare.yt,
  207. tcpsr.id as id,
  208. tcpsr.period,
  209. tcpsr.period_type as periodType,
  210. tcpsr.sb_id as sbId, tcpsr.num as num,
  211. part.name as sbPartName
  212. from t_spare_part_info spare
  213. left join t_sb_model_spare_bom tcpsr on tcpsr.spare_id=spare.id
  214. LEFT JOIN t_part_info part on tcpsr.sb_part_id = part.id
  215. where tcpsr.model_id = #{id}
  216. </select>
  217. <select id="selectSpareInfoListBySbId" resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  218. select spare.id as spareId, spare.no, spare.unite_no, spare.name, spare.type_id, spare.level,
  219. spare.initial_value, spare.producer_id,
  220. spare.unit,
  221. spare.unit_bz,spare.warn_status, spare.forecast_status,
  222. spare.unit_rate,
  223. spare.image,
  224. spare.qr_code,
  225. spare.zbh,spare.init_no,
  226. spare.gg_no, spare.name_no,
  227. spare.ggxh,
  228. spare.english_name,
  229. spare.zjm,
  230. spare.cd,
  231. spare.yt,
  232. tcpsr.id as id,
  233. tcpsr.period,
  234. tcpsr.period_type as periodType,
  235. tcpsr.model_id as modelId,
  236. tcpsr.sb_id as sbId,
  237. part.name as sbPartName
  238. from t_spare_part_info spare
  239. left join t_sb_model_spare_bom tcpsr on tcpsr.spare_id=spare.id
  240. LEFT JOIN t_part_info part on tcpsr.sb_part_id = part.id
  241. where tcpsr.sb_id = #{id}
  242. </select>
  243. <update id="updateBatch" parameterType="java.util.List">
  244. <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  245. update t_spare_part_info
  246. <set>
  247. <if test="item.parentTypeId != null">
  248. parent_type_id = #{item.parentTypeId},
  249. </if>
  250. <if test="item.childTypeId != null">
  251. child_type_id = #{item.childTypeId},
  252. </if>
  253. <if test="item.middleTypeId != null">
  254. middle_type_id = #{item.middleTypeId},
  255. </if>
  256. <if test="item.parentTypeId == null">
  257. parent_type_id = null,
  258. </if>
  259. <if test="item.childTypeId == null">
  260. child_type_id = null,
  261. </if>
  262. <if test="item.middleTypeId == null">
  263. middle_type_id = null,
  264. </if>
  265. <if test="item.parentNo != null">
  266. parent_no = #{item.parentNo},
  267. </if>
  268. <if test="item.middleNo != null">
  269. middle_no = #{item.middleNo},
  270. </if>
  271. <if test="item.warnStatus != null">
  272. warn_status = #{item.warnStatus},
  273. </if>
  274. <if test="item.forecastStatus != null">
  275. info.forecast_status = #{item.forecastStatus},
  276. </if>
  277. <if test="item.unit != null">
  278. child_no = #{item.childNo},
  279. </if>
  280. <if test="item.typeId != null">
  281. type_id = #{item.typeId},
  282. </if>
  283. <if test="item.ggxh != null">
  284. ggxh = #{item.ggxh},
  285. </if>
  286. <if test="item.name != null">
  287. name = #{item.name},
  288. </if>
  289. <if test="item.unit != null">
  290. unit = #{item.unit},
  291. </if>
  292. <if test="item.initNo != null">
  293. init_no = #{item.initNo},
  294. </if>
  295. <if test="item.initialValue != null">
  296. initial_value = #{item.initialValue}
  297. </if>
  298. </set>
  299. where id = #{item.id}
  300. </foreach>
  301. </update>
  302. </mapper>