SparePartInfoMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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="is_special" jdbcType="SMALLINT" property="isSpecial"/>
  23. <result column="initial_value" jdbcType="DOUBLE" property="initialValue"/>
  24. <result column="producer_id" jdbcType="VARCHAR" property="producerId"/>
  25. <result column="supplier_id" jdbcType="VARCHAR" property="supplierId"/>
  26. <result column="unit" jdbcType="VARCHAR" property="unit"/>
  27. <result column="warn_status" jdbcType="SMALLINT" property="warnStatus"/>
  28. <result column="forecast_status" jdbcType="SMALLINT" property="forecastStatus"/>
  29. <result column="unit_bz" jdbcType="SMALLINT" property="unitBz"/>
  30. <result column="unit_rate" jdbcType="DOUBLE" property="unitRate"/>
  31. <result column="max_stock" jdbcType="DOUBLE" property="maxStock"/>
  32. <result column="min_stock" jdbcType="DOUBLE" property="minStock"/>
  33. <result column="init_stock" jdbcType="DOUBLE" property="initStock"/>
  34. <result column="zbh" jdbcType="VARCHAR" property="zbh"/>
  35. <result column="ggxh" jdbcType="VARCHAR" property="ggxh"/>
  36. <result column="english_name" jdbcType="VARCHAR" property="englishName"/>
  37. <result column="zjm" jdbcType="VARCHAR" property="zjm"/>
  38. <result column="cd" jdbcType="INTEGER" property="cd"/>
  39. <result column="yt" jdbcType="INTEGER" property="yt"/>
  40. <result column="purchase_period" jdbcType="DECIMAL" property="purchasePeriod"/>
  41. <result column="age_period" jdbcType="DECIMAL" property="agePeriod"/>
  42. <result column="use_period" jdbcType="DECIMAL" property="usePeriod"/>
  43. <result column="params" jdbcType="VARCHAR" property="params"/>
  44. <result column="remark" jdbcType="VARCHAR" property="remark"/>
  45. <result column="created_user_id" jdbcType="VARCHAR" property="createdUserId"/>
  46. <result column="update_user_id" jdbcType="VARCHAR" property="updateUserId"/>
  47. <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
  48. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
  49. <association column="type_id" javaType="string" property="typeName"
  50. select="com.platform.dao.mapper.sqarepartmanage.SpareTypeMapper.selectNameById"/>
  51. <association column="producer_id" javaType="string" property="producerName"
  52. select="com.platform.dao.mapper.firm.FirmProducerMapper.selectNameById"/>
  53. <association column="supplier_id" javaType="string" property="supplierName"
  54. select="com.platform.dao.mapper.purchase.SupplierMapper.selectNameById"/>
  55. </resultMap>
  56. <sql id="Base_Column_List">
  57. id, no, unite_no, gg_no, name_no, name, type_id, level, initial_value, producer_id,
  58. unit,
  59. is_special,
  60. purchase_period,
  61. use_period,age_period,
  62. unit_bz,
  63. warn_status,forecast_status,
  64. unit_rate,
  65. image,
  66. qr_code,
  67. max_stock, min_stock,init_stock,supplier_id,
  68. remark, created_user_id, update_user_id, created_time, update_time,
  69. zbh,init_no,
  70. parent_type_id,
  71. child_type_id,
  72. middle_type_id,
  73. child_no,
  74. parent_no,
  75. middle_no,
  76. ggxh,
  77. english_name,
  78. zjm,
  79. cd,
  80. yt,
  81. brand
  82. </sql>
  83. <select id="selectPageList" parameterType="com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO"
  84. resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  85. select info.*, SUM(spareStore.num) currentStock
  86. from t_spare_part_info info
  87. LEFT JOIN t_spare_store spareStore on spareStore.spare_id = info.id
  88. <if test="producerName != null and producerName != ''">
  89. LEFT JOIN t_firm_producer producer on producer.id = info.producer_id
  90. </if>
  91. <if test="supplierName != null and supplierName != ''">
  92. LEFT JOIN t_supplier supplier on supplier.id = info.supplier_id
  93. </if>
  94. <where>
  95. <if test="spareIdList != null and spareIdList.size > 0">
  96. and sparestore.spare_id in
  97. <foreach item="item" index="index" collection="spareIdList" open="(" close=")" separator=",">
  98. #{item}
  99. </foreach>
  100. </if>
  101. <if test="warnStatusList != null and warnStatusList.size > 0">
  102. AND info.warn_status in
  103. <foreach item="item" index="index" collection="warnStatusList" open="(" close=")" separator=",">
  104. #{item}
  105. </foreach>
  106. </if>
  107. <if test="forecastStatusList != null and forecastStatusList.size > 0">
  108. AND info.forecast_status in
  109. <foreach item="item" index="index" collection="forecastStatusList" open="(" close=")" separator=",">
  110. #{item}
  111. </foreach>
  112. </if>
  113. <if test="typeId != null and typeId != ''">
  114. and info.type_id = #{typeId}
  115. </if>
  116. <if test="isSpecial != null and isSpecial != ''">
  117. and info.is_special = #{isSpecial}
  118. </if>
  119. <if test="producerName != null and producerName != ''">
  120. AND producer.name like concat('%',#{producerName},'%')
  121. </if>
  122. <if test="supplierName != null and supplierName != ''">
  123. AND supplier.name like concat('%',#{supplierName},'%')
  124. </if>
  125. <if test="keyword != null and keyword != ''">
  126. AND ( info.name like concat('%',#{keyword},'%') or
  127. info.no like concat('%',#{keyword},'%'))
  128. </if>
  129. <if test="name != null and name != ''">
  130. AND info.name = #{name}
  131. </if>
  132. <if test="warnStatus != null and warnStatus != ''">
  133. AND info.warn_status = #{warnStatus}
  134. </if>
  135. <if test="forecastStatus != null and forecastStatus != ''">
  136. AND info.forecast_status = #{forecastStatus}
  137. </if>
  138. <if test="ggxh != null and ggxh != ''">
  139. AND info.ggxh like concat('%',#{ggxh},'%')
  140. </if>
  141. <if test="initNo != null and initNo != ''">
  142. AND info.init_no like concat('%',#{initNo},'%')
  143. </if>
  144. <if test="yt != null">
  145. AND info.yt=#{yt}
  146. </if>
  147. <if test="storeId != null and storeId != ''">
  148. AND spare.store_id=#{storeId}
  149. </if>
  150. <if test="level != null and level != ''">
  151. AND info.level=#{level}
  152. </if>
  153. <if test="typeIds != null and typeIds.size > 0">
  154. AND info.type_id in
  155. <foreach item="item" index="index" collection="typeIds" open="(" close=")" separator=",">
  156. #{item}
  157. </foreach>
  158. </if>
  159. <if test="producerId != null and producerId != ''">
  160. AND info.producer_id=#{producerId}
  161. </if>
  162. <if test="supplierId != null and producerId != ''">
  163. AND info.supplier_id=#{supplierId}
  164. </if>
  165. <if test="parentTypeId != null and parentTypeId != ''">
  166. AND info.parent_type_id=#{parentTypeId}
  167. </if>
  168. <!-- <if test="typeId != null and typeId != ''">
  169. AND info.type_id=#{typeId}
  170. </if>-->
  171. <if test="parentNo != null and parentNo != ''">
  172. AND info.parent_no=#{parentNo}
  173. </if>
  174. <if test="childNo != null and childNo != ''">
  175. AND info.child_no=#{childNo}
  176. </if>
  177. <if test="searchMinStockWarn">
  178. AND info.min_stock is not null
  179. </if>
  180. <if test="searchMinStockWarn">
  181. AND info.warn_status = 0
  182. </if>
  183. <if test="searchType">
  184. AND info.type_id not in (select id from t_spare_type)
  185. </if>
  186. <if test="brand!=null">
  187. and info.brand like concat('%',#{brand},'%')
  188. </if>
  189. </where>
  190. group by info.id
  191. <if test="searchMinStockWarn">
  192. HAVING info.min_stock > SUM( spareStore.num )
  193. </if>
  194. </select>
  195. <select id="selectMaxNo" parameterType="java.lang.Object" resultType="java.lang.String">
  196. select max(no) from t_spare_part_info
  197. where type_id = #{value}
  198. </select>
  199. <select id="selectById" parameterType="java.lang.Object" resultMap="BaseResultMap">
  200. select
  201. <include refid="Base_Column_List"/>
  202. from t_spare_part_info
  203. where id = #{value}
  204. </select>
  205. <select id="selectNameById" parameterType="java.lang.Object" resultType="java.lang.String">
  206. select name
  207. from t_spare_part_info
  208. where id = #{value}
  209. </select>
  210. <select id="selectSpareInfoList" resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  211. select spare.id as spareId, spare.no, spare.unite_no, spare.name, spare.type_id, spare.level,
  212. spare.initial_value, spare.producer_id,
  213. spare.unit,
  214. spare.unit_bz,spare.warn_status, spare.forecast_status,
  215. spare.unit_rate,
  216. spare.image,
  217. spare.qr_code,
  218. spare.zbh,spare.init_no,
  219. spare.gg_no, spare.name_no,
  220. spare.ggxh,
  221. spare.english_name,
  222. spare.zjm,
  223. spare.cd,
  224. spare.yt,
  225. tcpsr.id as id,
  226. tcpsr.period,
  227. tcpsr.period_type as periodType,
  228. tcpsr.sb_id as sbId, tcpsr.num as num,
  229. part.name as sbPartName
  230. from t_spare_part_info spare
  231. left join t_sb_model_spare_bom tcpsr on tcpsr.spare_id=spare.id
  232. LEFT JOIN t_part_info part on tcpsr.sb_part_id = part.id
  233. where tcpsr.sb_id = #{id}
  234. </select>
  235. <select id="selectSpareInfoListBySbId" resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  236. select spare.id as spareId, spare.no, spare.unite_no, spare.name, spare.type_id, spare.level,
  237. spare.initial_value, spare.producer_id,
  238. spare.unit,
  239. spare.unit_bz,spare.warn_status, spare.forecast_status,
  240. spare.unit_rate,
  241. spare.image,
  242. spare.qr_code,
  243. spare.zbh,spare.init_no,
  244. spare.gg_no, spare.name_no,
  245. spare.ggxh,
  246. spare.english_name,
  247. spare.zjm,
  248. spare.cd,
  249. spare.yt,
  250. tcpsr.id as id,
  251. tcpsr.period,
  252. tcpsr.period_type as periodType,
  253. tcpsr.model_id as modelId,
  254. tcpsr.sb_id as sbId,
  255. part.name as sbPartName
  256. from t_spare_part_info spare
  257. left join t_sb_model_spare_bom tcpsr on tcpsr.spare_id=spare.id
  258. LEFT JOIN t_part_info part on tcpsr.sb_part_id = part.id
  259. where tcpsr.sb_id = #{id}
  260. </select>
  261. <update id="updateBatch" parameterType="java.util.List">
  262. <foreach collection="list" item="item" index="index" open="" close="" separator=";">
  263. update t_spare_part_info
  264. <set>
  265. <if test="item.parentTypeId != null">
  266. parent_type_id = #{item.parentTypeId},
  267. </if>
  268. <if test="item.childTypeId != null">
  269. child_type_id = #{item.childTypeId},
  270. </if>
  271. <if test="item.middleTypeId != null">
  272. middle_type_id = #{item.middleTypeId},
  273. </if>
  274. <if test="item.parentTypeId == null">
  275. parent_type_id = null,
  276. </if>
  277. <if test="item.childTypeId == null">
  278. child_type_id = null,
  279. </if>
  280. <if test="item.middleTypeId == null">
  281. middle_type_id = null,
  282. </if>
  283. <if test="item.parentNo != null">
  284. parent_no = #{item.parentNo},
  285. </if>
  286. <if test="item.middleNo != null">
  287. middle_no = #{item.middleNo},
  288. </if>
  289. <if test="item.warnStatus != null">
  290. warn_status = #{item.warnStatus},
  291. </if>
  292. <if test="item.forecastStatus != null">
  293. forecast_status = #{item.forecastStatus},
  294. </if>
  295. <if test="item.isSpecial != null">
  296. is_special = #{item.isSpecial},
  297. </if>
  298. <if test="item.unit != null">
  299. child_no = #{item.childNo},
  300. </if>
  301. <if test="item.typeId != null">
  302. type_id = #{item.typeId},
  303. </if>
  304. <if test="item.ggxh != null">
  305. ggxh = #{item.ggxh},
  306. </if>
  307. <if test="item.name != null">
  308. name = #{item.name},
  309. </if>
  310. <if test="item.unit != null">
  311. unit = #{item.unit},
  312. </if>
  313. <if test="item.initNo != null">
  314. init_no = #{item.initNo},
  315. </if>
  316. <if test="item.initialValue != null">
  317. initial_value = #{item.initialValue}
  318. </if>
  319. </set>
  320. where id = #{item.id}
  321. </foreach>
  322. </update>
  323. <!-- 维修和保养获取备件信息List -->
  324. <select id="getSpareListBySbInfo" parameterType="com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO"
  325. resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  326. select spi.* from t_sb_model_spare_bom sm left join t_spare_part_info spi on sm.spare_id = spi.id
  327. <where>
  328. <if test="sbId != null">
  329. and sm.sb_id = #{sbId}
  330. </if>
  331. <if test="name != null and name != ''">
  332. and spi.name like concat('%',#{name},'%')
  333. </if>
  334. <if test="isSpecial != null">
  335. and spi.is_special = #{isSpecial}
  336. </if>
  337. </where>
  338. </select>
  339. <select id="getInOrOut" parameterType="com.platform.dao.dto.sqarepartmanage.SparePartInfoDTO"
  340. resultType="com.platform.dao.vo.query.sparepartmanage.SparePartInfoVO">
  341. select info.*, SUM(spareStore.num) currentStock,store.name as storeName,spareStore.id as spareStoreId
  342. from t_spare_part_info info
  343. LEFT JOIN t_spare_store spareStore on spareStore.spare_id = info.id
  344. left join t_store store on spareStore.store_id = store.id
  345. <if test="producerName != null and producerName != ''">
  346. LEFT JOIN t_firm_producer producer on producer.id = info.producer_id
  347. </if>
  348. <if test="supplierName != null and supplierName != ''">
  349. LEFT JOIN t_supplier supplier on supplier.id = info.supplier_id
  350. </if>
  351. <where>
  352. <if test="spareIdList != null and spareIdList.size > 0">
  353. and sparestore.spare_id in
  354. <foreach item="item" index="index" collection="spareIdList" open="(" close=")" separator=",">
  355. #{item}
  356. </foreach>
  357. </if>
  358. <if test="warnStatusList != null and warnStatusList.size > 0">
  359. AND info.warn_status in
  360. <foreach item="item" index="index" collection="warnStatusList" open="(" close=")" separator=",">
  361. #{item}
  362. </foreach>
  363. </if>
  364. <if test="forecastStatusList != null and forecastStatusList.size > 0">
  365. AND info.forecast_status in
  366. <foreach item="item" index="index" collection="forecastStatusList" open="(" close=")" separator=",">
  367. #{item}
  368. </foreach>
  369. </if>
  370. <if test="typeId != null and typeId != ''">
  371. and info.type_id = #{typeId}
  372. </if>
  373. <if test="isSpecial != null and isSpecial != ''">
  374. and info.is_special = #{isSpecial}
  375. </if>
  376. <if test="producerName != null and producerName != ''">
  377. AND producer.name like concat('%',#{producerName},'%')
  378. </if>
  379. <if test="supplierName != null and supplierName != ''">
  380. AND supplier.name like concat('%',#{supplierName},'%')
  381. </if>
  382. <if test="keyword != null and keyword != ''">
  383. AND ( info.name like concat('%',#{keyword},'%') or
  384. info.no like concat('%',#{keyword},'%'))
  385. </if>
  386. <if test="name != null and name != ''">
  387. AND info.name = #{name}
  388. </if>
  389. <if test="warnStatus != null and warnStatus != ''">
  390. AND info.warn_status = #{warnStatus}
  391. </if>
  392. <if test="forecastStatus != null and forecastStatus != ''">
  393. AND info.forecast_status = #{forecastStatus}
  394. </if>
  395. <if test="ggxh != null and ggxh != ''">
  396. AND info.ggxh like concat('%',#{ggxh},'%')
  397. </if>
  398. <if test="initNo != null and initNo != ''">
  399. AND info.init_no like concat('%',#{initNo},'%')
  400. </if>
  401. <if test="yt != null">
  402. AND info.yt=#{yt}
  403. </if>
  404. <if test="storeId != null and storeId != ''">
  405. AND spare.store_id=#{storeId}
  406. </if>
  407. <if test="level != null and level != ''">
  408. AND info.level=#{level}
  409. </if>
  410. <if test="typeIds != null and typeIds.size > 0">
  411. AND info.type_id in
  412. <foreach item="item" index="index" collection="typeIds" open="(" close=")" separator=",">
  413. #{item}
  414. </foreach>
  415. </if>
  416. <if test="producerId != null and producerId != ''">
  417. AND info.producer_id=#{producerId}
  418. </if>
  419. <if test="supplierId != null and producerId != ''">
  420. AND info.supplier_id=#{supplierId}
  421. </if>
  422. <if test="parentTypeId != null and parentTypeId != ''">
  423. AND info.parent_type_id=#{parentTypeId}
  424. </if>
  425. <!-- <if test="typeId != null and typeId != ''">
  426. AND info.type_id=#{typeId}
  427. </if>-->
  428. <if test="parentNo != null and parentNo != ''">
  429. AND info.parent_no=#{parentNo}
  430. </if>
  431. <if test="childNo != null and childNo != ''">
  432. AND info.child_no=#{childNo}
  433. </if>
  434. <if test="searchMinStockWarn">
  435. AND info.min_stock is not null
  436. </if>
  437. <if test="searchMinStockWarn">
  438. AND info.warn_status = 0
  439. </if>
  440. <if test="searchType">
  441. AND info.type_id not in (select id from t_spare_type)
  442. </if>
  443. <if test="brand!=null">
  444. and info.brand like concat('%',#{brand},'%')
  445. </if>
  446. </where>
  447. group by info.id
  448. <if test="searchMinStockWarn">
  449. HAVING info.min_stock > SUM( spareStore.num )
  450. </if>
  451. </select>
  452. </mapper>