YpInDetlMapper.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. package cn.hnthyy.thmz.mapper.his.yp;
  2. import cn.hnthyy.thmz.entity.his.yp.YpInDetl;
  3. import cn.hnthyy.thmz.vo.YpInDetlVo;
  4. import org.apache.ibatis.annotations.*;
  5. import java.util.List;
  6. import java.util.Map;
  7. /**
  8. * 药库入库持久化类
  9. */
  10. public interface YpInDetlMapper {
  11. /**
  12. * 查询药品入库信息
  13. *
  14. * @param ypInDetl
  15. * @return
  16. */
  17. @Select("<script>" +
  18. "select manu_code,rtrim(manu_no)manu_no,rtrim(in_docu_no)in_docu_no,in_seri,rtrim(charge_code)charge_code,buy_price,avg_price,buy_amt,group_no,serial," +
  19. " supply_code,eff_date,current_stock,in_date from yp_in_detl WITH(NOLOCK) " +
  20. "<where>" +
  21. " <if test=\"chargeCode != null and chargeCode != ''\">" +
  22. " AND charge_code = #{chargeCode}" +
  23. " </if>" +
  24. " <if test=\"inSeri != null and inSeri != ''\">" +
  25. " AND in_seri = #{inSeri}" +
  26. " </if>" +
  27. " <if test=\"serial != null and serial != ''\">" +
  28. " AND serial = #{serial}" +
  29. " </if>" +
  30. " <if test=\"inDocuNo != null and inDocuNo != ''\">" +
  31. " AND in_docu_no = #{inDocuNo}" +
  32. " </if>" +
  33. " <if test=\"groupNo != null and groupNo != ''\">" +
  34. " AND group_no = #{groupNo}" +
  35. " </if>" +
  36. " <if test=\"currentStock != null\">" +
  37. " AND current_stock > ${currentStock}" +
  38. " </if>" +
  39. "</where>" +
  40. "</script>")
  41. List<YpInDetl> selectYpInDetl(YpInDetl ypInDetl);
  42. /**
  43. * 分页查询入库单记录
  44. *
  45. * @param ypInDetlVo
  46. * @return
  47. */
  48. @Select("<script>" +
  49. "select top ${pageSize} * " +
  50. " from (select ROW_NUMBER() OVER (ORDER BY in_docu_no DESC)AS RowNumber," +
  51. " in_date =max(a.in_date)," +
  52. " rept_no =rtrim(max(a.rept_no))," +
  53. " supply_code =max(a.supply_code)," +
  54. " in_docu_no =rtrim(a.in_docu_no)," +
  55. " purchaser =max(a.purchaser)," +
  56. " checker =max(a.checker)," +
  57. " buy_value=sum(round(buy_amt * buy_price,2))," +
  58. " pack_value=sum(round(buy_amt * pack_retprice,2))" +
  59. " FROM yp_in_detl a WITH(NOLOCK)" +
  60. "<where> " +
  61. "<when test='inType != null'>" +
  62. " and in_type in (${inType})" +
  63. "</when>" +
  64. "<when test='inDocuNo != null'>" +
  65. " and in_docu_no=#{inDocuNo}" +
  66. "</when>" +
  67. "<when test='confirmFlag != null'>" +
  68. " and isnull(a.confirm_flag,'0') = #{confirmFlag}" +
  69. "</when>" +
  70. "<when test='reptNo != null'>" +
  71. " and a.rept_no = #{reptNo}" +
  72. "</when>" +
  73. "<when test='groupNo != null'>" +
  74. " and group_no=#{groupNo}" +
  75. "</when>" +
  76. "<when test='beginTime != null'>" +
  77. " and in_date <![CDATA[>=]]> #{beginTime}" +
  78. "</when>" +
  79. "<when test='endTime != null'>" +
  80. " and in_date <![CDATA[<=]]> #{endTime}" +
  81. "</when>" +
  82. "</where>" +
  83. " group by a.in_docu_no) as A WHERE RowNumber >#{pageSize}*#{pageIndex} order by RowNumber asc" +
  84. "</script>")
  85. List<YpInDetlVo> selectYpInDetlPage(YpInDetlVo ypInDetlVo);
  86. /**
  87. * 查询入库单记录总数
  88. *
  89. * @param ypInDetlVo
  90. * @return
  91. */
  92. @Select("<script>" +
  93. " select count(1) from (select a.in_docu_no" +
  94. " FROM yp_in_detl a WITH(NOLOCK)" +
  95. "<where> " +
  96. "<when test='inType != null'>" +
  97. " and in_type in (${inType})" +
  98. "</when>" +
  99. "<when test='inDocuNo != null'>" +
  100. " and in_docu_no=#{inDocuNo}" +
  101. "</when>" +
  102. "<when test='confirmFlag != null'>" +
  103. " and isnull(a.confirm_flag,'0') = #{confirmFlag}" +
  104. "</when>" +
  105. "<when test='reptNo != null'>" +
  106. " and a.rept_no = #{reptNo}" +
  107. "</when>" +
  108. "<when test='groupNo != null'>" +
  109. " and group_no=#{groupNo}" +
  110. "</when>" +
  111. "<when test='beginTime != null'>" +
  112. " and in_date <![CDATA[>=]]> #{beginTime}" +
  113. "</when>" +
  114. "<when test='endTime != null'>" +
  115. " and in_date <![CDATA[<=]]> #{endTime}" +
  116. "</when>" +
  117. "</where>" +
  118. " group by a.in_docu_no)b" +
  119. "</script>")
  120. int selectYpInDetlCount(YpInDetlVo ypInDetlVo);
  121. /**
  122. * 查询记录详细
  123. *
  124. * @param ypInDetlVo
  125. * @return
  126. */
  127. @Select("<script>" +
  128. "SELECT yp.in_date," +
  129. " yp.in_seri," +
  130. " rtrim(yp.charge_code)charge_code," +
  131. " yp.serial," +
  132. " yp.pack_retprice," +
  133. " yp.buy_price," +
  134. " yp.buy_amt," +
  135. " yp.eff_date," +
  136. " rtrim(yp.manu_no)manu_no," +
  137. " rtrim(yp.rept_no)rept_no," +
  138. " rtrim(yp.in_docu_no)in_docu_no," +
  139. " yp.supply_code," +
  140. " yp.manu_code," +
  141. " rtrim(yp.license_no)license_no," +
  142. " yp.purchaser," +
  143. " yp.checker," +
  144. " yp.in_comment," +
  145. " yp.in_type," +
  146. " yp.acct_type," +
  147. " yp.stock_amount," +
  148. " yp.fix_price," +
  149. " yp.group_no," +
  150. " yp.acct_date," +
  151. " yp.current_stock," +
  152. " yp.kl," +
  153. " yp.sys_date," +
  154. " yp.fp_date," +
  155. " rtrim(yp.hg_flag) as hg_flag," +
  156. " '0' as new_flag," +
  157. " yp.buy_amt," +
  158. " yp.confirm_flag," +
  159. " yp.confirm_id," +
  160. " yp.accept_id," +
  161. " yp.rept_date," +
  162. " yp.confirm_date," +
  163. " yp.producing_date, " +
  164. " zd.national_code " +
  165. " FROM yp_in_detl yp WITH(NOLOCK)" +
  166. " left join yp_zd_dict zd on yp.charge_code = zd.code and yp.serial = zd.serial " +
  167. "<where>" +
  168. " <if test=\"chargeCode != null and chargeCode != ''\">" +
  169. " AND yp.charge_code=#{chargeCode}" +
  170. " </if>" +
  171. " <if test=\"inSeri != null and inSeri != ''\">" +
  172. " AND yp.in_seri=#{inSeri}" +
  173. " </if>" +
  174. " <if test=\"serial != null and serial != ''\">" +
  175. " AND yp.serial=#{serial}" +
  176. " </if>" +
  177. " <if test=\"inDocuNo != null and inDocuNo != ''\">" +
  178. " AND yp.in_docu_no=#{inDocuNo}" +
  179. " </if>" +
  180. " <if test=\"supplyCode != null and supplyCode != ''\">" +
  181. " AND yp.supply_code = #{supplyCode}" +
  182. " </if>" +
  183. " <if test=\"groupNo != null and groupNo != ''\">" +
  184. " AND yp.group_no=#{groupNo}" +
  185. " </if>" +
  186. " <if test=\"serialTh != null and serialTh != ''\">" +
  187. " AND yp.serial_th=#{serialTh}" +
  188. " </if>" +
  189. " <if test=\"beginTime != null and beginTime != ''\">" +
  190. " AND yp.in_date &gt;=#{beginTime}" +
  191. " </if>" +
  192. " <if test=\"endTime != null and endTime != ''\">" +
  193. " AND yp.in_date &lt;=#{endTime}" +
  194. " </if>" +
  195. "</where>" +
  196. " order by yp.supply_code,yp.in_docu_no"+
  197. "</script>")
  198. List<YpInDetl> selectYpInDetlDetailed(YpInDetlVo ypInDetlVo);
  199. /**
  200. * 分页查询记录详细
  201. *
  202. * @param ypInDetlVo
  203. * @return
  204. */
  205. @Select("<script>" +
  206. "select top ${pageSize} * " +
  207. " from (select ROW_NUMBER() OVER (ORDER BY in_docu_no DESC)AS RowNumber," +
  208. " in_date, " +
  209. " in_seri, " +
  210. " rtrim(charge_code)charge_code, " +
  211. " serial, " +
  212. " pack_retprice, " +
  213. " buy_price, " +
  214. " buy_amt, " +
  215. " eff_date, " +
  216. " rtrim(manu_no)manu_no, " +
  217. " rtrim(rept_no)rept_no, " +
  218. " rtrim(in_docu_no)in_docu_no, " +
  219. " supply_code, " +
  220. " manu_code, " +
  221. " rtrim(license_no)license_no, " +
  222. " purchaser, " +
  223. " checker, " +
  224. " in_comment, " +
  225. " in_type, " +
  226. " acct_type, " +
  227. " stock_amount, " +
  228. " fix_price, " +
  229. " group_no, " +
  230. " acct_date, " +
  231. " current_stock, " +
  232. " kl, " +
  233. " sys_date, " +
  234. " fp_date, " +
  235. " rtrim(hg_flag) as hg_flag, " +
  236. " confirm_flag, " +
  237. " confirm_id, " +
  238. " accept_id, " +
  239. " rept_date, " +
  240. " confirm_date, " +
  241. " producing_date " +
  242. " FROM yp_in_detl a WITH(NOLOCK)" +
  243. "<where> " +
  244. " and confirm_flag=1" +
  245. "<when test='inType != null'>" +
  246. " and in_type in (${inType})" +
  247. "</when>" +
  248. "<when test='chargeCode != null'>" +
  249. " and charge_code=#{chargeCode}" +
  250. "</when>" +
  251. "<when test='manuCode != null'>" +
  252. " and manu_code=#{manuCode}" +
  253. "</when>" +
  254. "<when test='supplyCode != null'>" +
  255. " and supply_code=#{supplyCode}" +
  256. "</when>" +
  257. "<when test='inDocuNo != null'>" +
  258. " and in_docu_no=#{inDocuNo}" +
  259. "</when>" +
  260. "<when test='confirmFlag != null'>" +
  261. " and isnull(a.confirm_flag,'0') = #{confirmFlag}" +
  262. "</when>" +
  263. "<when test='reptNo != null'>" +
  264. " and a.rept_no = #{reptNo}" +
  265. "</when>" +
  266. "<when test='groupNo != null'>" +
  267. " and group_no=#{groupNo}" +
  268. "</when>" +
  269. "<when test='beginTime != null'>" +
  270. " and in_date <![CDATA[>=]]> #{beginTime}" +
  271. "</when>" +
  272. "<when test='endTime != null'>" +
  273. " and in_date <![CDATA[<=]]> #{endTime}" +
  274. "</when>" +
  275. "</where>" +
  276. " ) as A WHERE RowNumber >#{pageSize}*#{pageIndex} order by RowNumber asc" +
  277. "</script>")
  278. List<YpInDetl> selectYpInDetlDetailedPage(YpInDetlVo ypInDetlVo);
  279. /**
  280. * 查询入库单详细记录总数
  281. *
  282. * @param ypInDetlVo
  283. * @return
  284. */
  285. @Select("<script>" +
  286. " select count(1) from (select a.in_docu_no" +
  287. " FROM yp_in_detl a WITH(NOLOCK)" +
  288. "<where> " +
  289. " and confirm_flag=1" +
  290. "<when test='inType != null'>" +
  291. " and in_type in (${inType})" +
  292. "</when>" +
  293. "<when test='chargeCode != null'>" +
  294. " and charge_code=#{chargeCode}" +
  295. "</when>" +
  296. "<when test='inDocuNo != null'>" +
  297. " and in_docu_no=#{inDocuNo}" +
  298. "</when>" +
  299. "<when test='confirmFlag != null'>" +
  300. " and isnull(a.confirm_flag,'0') = #{confirmFlag}" +
  301. "</when>" +
  302. "<when test='reptNo != null'>" +
  303. " and a.rept_no = #{reptNo}" +
  304. "</when>" +
  305. "<when test='groupNo != null'>" +
  306. " and group_no=#{groupNo}" +
  307. "</when>" +
  308. "<when test='beginTime != null'>" +
  309. " and in_date <![CDATA[>=]]> #{beginTime}" +
  310. "</when>" +
  311. "<when test='endTime != null'>" +
  312. " and in_date <![CDATA[<=]]> #{endTime}" +
  313. "</when>" +
  314. "</where>" +
  315. " )b" +
  316. "</script>")
  317. int selectYpInDetlDetailedCount(YpInDetlVo ypInDetlVo);
  318. /**
  319. * 删除入库记录单
  320. *
  321. * @param inDocuNo
  322. * @return
  323. */
  324. @Delete("delete from yp_in_detl where in_docu_no=#{inDocuNo}")
  325. int deleteYpInDetlByInDocuNo(@Param("inDocuNo") String inDocuNo);
  326. /**
  327. * 删除入库药品信息
  328. *
  329. * @param inDocuNo
  330. * @param inSeri
  331. * @return
  332. */
  333. @Delete("delete from yp_in_detl where in_docu_no=#{inDocuNo} and in_seri=#{inSeri}")
  334. int deleteYpInDetl(@Param("inDocuNo") String inDocuNo, @Param("inSeri") Integer inSeri);
  335. /**
  336. * 保存入库记录单
  337. *
  338. * @param ypInDetlList
  339. * @return
  340. */
  341. @Insert("<script>" +
  342. "insert into yp_in_detl ( in_date , in_seri , charge_code , serial , buy_amt , buy_price , eff_date , manu_no , rept_no , in_docu_no , supply_code , manu_code , " +
  343. "license_no , purchaser , checker , in_comment , in_type , pack_retprice , acct_type , fix_price , group_no , current_stock , sys_date , rept_date , input_id , stock_amount , avg_price,producing_date )" +
  344. " values" +
  345. " <foreach item='item' collection='ypInDetlList' separator=','> " +
  346. " (#{item.inDate,jdbcType=TIMESTAMP},#{item.inSeri,jdbcType=BIGINT},#{item.chargeCode,jdbcType=VARCHAR},#{item.serial,jdbcType=VARCHAR},#{item.buyAmt,jdbcType=DOUBLE}," +
  347. " cast(#{item.buyPrice} as decimal(15,3)),#{item.effDate,jdbcType=DATE},#{item.manuNo,jdbcType=VARCHAR},#{item.reptNo,jdbcType=VARCHAR}," +
  348. " #{item.inDocuNo,jdbcType=VARCHAR},#{item.supplyCode,jdbcType=VARCHAR},#{item.manuCode,jdbcType=VARCHAR},#{item.licenseNo,jdbcType=VARCHAR}," +
  349. " #{item.purchaser,jdbcType=VARCHAR},#{item.checker,jdbcType=VARCHAR},#{item.inComment,jdbcType=VARCHAR},#{item.inType,jdbcType=VARCHAR}," +
  350. " cast(#{item.packRetprice} as decimal(15,3)),#{item.acctType,jdbcType=VARCHAR},cast(#{item.fixPrice} as decimal(15,3)),#{item.groupNo,jdbcType=VARCHAR}," +
  351. " #{item.currentStock,jdbcType=DOUBLE},#{item.sysDate,jdbcType=TIMESTAMP},#{item.reptDate,jdbcType=DATE},#{item.inputId,jdbcType=VARCHAR}," +
  352. " #{item.stockAmount,jdbcType=DOUBLE},#{item.avgPrice,jdbcType=DOUBLE},#{item.producingDate,jdbcType=DATE})" +
  353. " </foreach>" +
  354. "</script>")
  355. int insertYpInDetlList(@Param("ypInDetlList") List<YpInDetl> ypInDetlList);
  356. /**
  357. * 保存入库记录单
  358. *
  359. * @param sql
  360. * @return
  361. */
  362. @Insert("<script>" +
  363. "insert into yp_in_detl ${sql}"+
  364. "</script>")
  365. int insertYpInDetl(@Param("sql") String sql);
  366. /**
  367. * 更新入库单信息
  368. *
  369. * @return
  370. */
  371. @Update({"<script>",
  372. "update yp_in_detl ",
  373. "<trim prefix='set' prefixOverrides=','>",
  374. "<when test='buyPrice!=null'>",
  375. ",buy_price =#{buyPrice,jdbcType=DOUBLE}",
  376. "</when>",
  377. "<when test='buyAmt!=null'>",
  378. ",buy_amt =#{buyAmt,jdbcType=DOUBLE}",
  379. "</when>",
  380. "<when test='confirmFlag!=null'>",
  381. ",confirm_flag =#{confirmFlag}",
  382. "</when>",
  383. "<when test='confirmId!=null'>",
  384. ",confirm_id =#{confirmId}",
  385. "</when>",
  386. "<when test='confirmDate!=null'>",
  387. ",confirm_date =#{confirmDate}",
  388. "</when>",
  389. "<when test='currentStock!=null'>",
  390. ",current_stock =current_stock+${currentStock}",
  391. "</when>",
  392. "</trim>",
  393. "<where>" +
  394. " <if test=\"inDocuNo != null and inDocuNo != ''\">" +
  395. " AND in_docu_no = #{inDocuNo}" +
  396. " </if>" +
  397. " <if test=\"inSeri != null and inSeri != ''\">" +
  398. " AND in_seri = #{inSeri}" +
  399. " </if>" +
  400. " <if test=\"chargeCode != null and chargeCode != ''\">" +
  401. " AND charge_code = #{chargeCode}" +
  402. " </if>" +
  403. " <if test=\"serial != null and serial != ''\">" +
  404. " AND serial = #{serial}" +
  405. " </if>" +
  406. "</where>" +
  407. "</script>"})
  408. int updateYpInDetl(YpInDetl ypInDetl);
  409. /**
  410. * 入库验收分类统计金额
  411. *
  412. * @param ypInDetlVo
  413. * @return
  414. */
  415. @Select("<script>" +
  416. "SELECT c.name," +
  417. " c.yp_type as ypType," +
  418. " buyMoney=sum(cast(a.buy_price* a.buy_amt as decimal(18,2)))," +
  419. " packMoney=sum(cast(a.pack_retprice * a.buy_amt as decimal(18,2)))" +
  420. "FROM yp_in_detl a WITH(NOLOCK),yp_zd_dict b WITH(NOLOCK),yp_zd_drug_kind c WITH(NOLOCK)" +
  421. "<where>" +
  422. " AND a.charge_code=b.code" +
  423. " AND a.serial=b.serial" +
  424. " AND b.drug_kind=c.code" +
  425. " <if test=\"inDocuNo != null and inDocuNo != ''\">" +
  426. " AND in_docu_no=#{inDocuNo}" +
  427. " </if>" +
  428. " <if test=\"supplyCode != null and supplyCode != ''\">" +
  429. " AND supply_code = #{supplyCode}" +
  430. " </if>" +
  431. " <if test=\"groupNo != null and groupNo != ''\">" +
  432. " AND group_no=#{groupNo}" +
  433. " </if>" +
  434. " <if test=\"beginTime != null and beginTime != ''\">" +
  435. " AND in_date &gt;=#{beginTime}" +
  436. " </if>" +
  437. " <if test=\"endTime != null and endTime != ''\">" +
  438. " AND in_date &lt;=#{endTime}" +
  439. " </if>" +
  440. "</where>" +
  441. " group by c.name,c.yp_type"+
  442. "</script>")
  443. List<Map<String, Object>> selectYpInDetlAccSum(YpInDetlVo ypInDetlVo);
  444. /**
  445. * 查询现时库存大于0的入库记录
  446. * @param ypInDetl
  447. * @return
  448. */
  449. @Select("<script>"+
  450. "SELECT in_date,in_seri,rtrim(charge_code)charge_code,serial,pack_retprice," +
  451. " buy_price,buy_amt, eff_date, manu_no," +
  452. " rept_no,rtrim(in_docu_no)in_docu_no,supply_code,manu_code," +
  453. " license_no,purchaser,checker,in_comment," +
  454. " in_type,acct_type,stock_amount,fix_price,group_no,acct_date," +
  455. " current_stock,kl,sys_date,fp_date,hg_flag" +
  456. " FROM yp_in_detl WITH(NOLOCK)" +
  457. "<where>" +
  458. " current_stock > 0" +
  459. " <if test=\"chargeCode != null and chargeCode != ''\">" +
  460. " AND charge_code=#{chargeCode}" +
  461. " </if>" +
  462. " <if test=\"groupNo != null and groupNo != ''\">" +
  463. " AND group_no = #{groupNo}" +
  464. " </if>" +
  465. " <if test=\"supplyCode != null and supplyCode != ''\">" +
  466. " AND supply_code=#{supplyCode}" +
  467. " </if>" +
  468. " <if test=\"reptNo != null and reptNo != ''\">" +
  469. " AND rept_no=#{reptNo}" +
  470. " </if>" +
  471. " <if test=\"inDocuNo != null and inDocuNo != ''\">" +
  472. " AND in_docu_no=#{inDocuNo}" +
  473. " </if>" +
  474. "</where>" +
  475. "</script>")
  476. List<YpInDetl> selectCurrentStockGreaterZero(YpInDetl ypInDetl);
  477. /**
  478. * 统计供应商药品购入汇总
  479. * @param map
  480. * @return
  481. */
  482. @Select("<script>"+
  483. "SELECT " +
  484. " buyAmt = sum(buy_amt),\n" +
  485. " packRetpriceSum = sum(buy_amt *convert(decimal(18,4), pack_retprice)),\n" +
  486. " buyPriceSum = sum(buy_amt * convert(decimal(18,4),buy_price)),\n" +
  487. " reptNoSum=count(distinct rept_no),\n" +
  488. " manuCode=max(manu_code),\n" +
  489. " supplyCode=max(supply_code),\n" +
  490. " in_docu_no AS inDocuNo" +
  491. " FROM yp_in_detl WITH(NOLOCK)" +
  492. "<where>" +
  493. " <if test=\"beginDate != null and beginDate != ''\">" +
  494. " and in_date <![CDATA[>=]]> #{beginDate}"+
  495. " </if>"+
  496. " <if test=\"endDate != null and endDate != ''\">" +
  497. " and in_date <![CDATA[<=]]> #{endDate}"+
  498. " </if>"+
  499. " <if test=\"groupNo != null and groupNo != ''\">" +
  500. " AND group_no = #{groupNo}" +
  501. " </if>" +
  502. " GROUP BY supply_code,in_docu_no" +
  503. " ORDER BY supply_code,sum(buy_amt * buy_price) DESC" +
  504. "</where>" +
  505. "</script>")
  506. List<Map<String,Object>> selectDrugSupplySum(Map map);
  507. /**
  508. * 统计供应商药品购入明细
  509. * @param map
  510. * @return
  511. */
  512. @Select("<script>"+
  513. "SELECT chargeCode=rtrim(charge_code)," +
  514. " serial," +
  515. " buyAmt = sum(buy_amt),\n" +
  516. " packRetpriceSum = sum(buy_amt *convert(decimal(18,4), pack_retprice)),\n" +
  517. " buyPriceSum = sum(buy_amt * convert(decimal(18,4),buy_price)),\n" +
  518. " reptNoSum=count(distinct rept_no),\n" +
  519. " manuCode=max(manu_code),\n" +
  520. " supplyCode=max(supply_code)" +
  521. " FROM yp_in_detl WITH(NOLOCK)" +
  522. "<where>" +
  523. " <if test=\"beginDate != null and beginDate != ''\">" +
  524. " and in_date <![CDATA[>=]]> #{beginDate}"+
  525. " </if>"+
  526. " <if test=\"endDate != null and endDate != ''\">" +
  527. " and in_date <![CDATA[<=]]> #{endDate}"+
  528. " </if>"+
  529. " <if test=\"groupNo != null and groupNo != ''\">" +
  530. " AND group_no = #{groupNo}" +
  531. " </if>" +
  532. " GROUP BY charge_code," +
  533. " serial ," +
  534. " supply_code" +
  535. " order by supply_code,sum(buy_amt * buy_price) desc" +
  536. "</where>" +
  537. "</script>")
  538. List<Map<String,Object>> selectDrugSupplyDetailed(Map map);
  539. /**
  540. * 统计生产厂家药品购入汇总
  541. * @param map
  542. * @return
  543. */
  544. @Select("<script>"+
  545. "SELECT " +
  546. " buyAmt = sum(buy_amt),\n" +
  547. " packRetpriceSum = sum(buy_amt *convert(decimal(18,4), pack_retprice)),\n" +
  548. " buyPriceSum = sum(buy_amt * convert(decimal(18,4),buy_price)),\n" +
  549. " reptNoSum=count(distinct rept_no),\n" +
  550. " manuCode=max(manu_code),\n" +
  551. " supplyCode=max(supply_code)" +
  552. " FROM yp_in_detl WITH(NOLOCK)" +
  553. "<where>" +
  554. " <if test=\"beginDate != null and beginDate != ''\">" +
  555. " and in_date <![CDATA[>=]]> #{beginDate}"+
  556. " </if>"+
  557. " <if test=\"endDate != null and endDate != ''\">" +
  558. " and in_date <![CDATA[<=]]> #{endDate}"+
  559. " </if>"+
  560. " <if test=\"groupNo != null and groupNo != ''\">" +
  561. " AND group_no = #{groupNo}" +
  562. " </if>" +
  563. " GROUP BY manu_code" +
  564. " ORDER BY manu_code,sum(buy_amt * buy_price) DESC" +
  565. "</where>" +
  566. "</script>")
  567. List<Map<String,Object>> selectDrugManuSum(Map map);
  568. /**
  569. * 统计生产厂家药品购入明细
  570. * @param map
  571. * @return
  572. */
  573. @Select("<script>"+
  574. "SELECT chargeCode=rtrim(charge_code)," +
  575. " serial," +
  576. " buyAmt = sum(buy_amt),\n" +
  577. " packRetpriceSum = sum(buy_amt *convert(decimal(18,4), pack_retprice)),\n" +
  578. " buyPriceSum = sum(buy_amt * convert(decimal(18,4),buy_price)),\n" +
  579. " reptNoSum=count(distinct rept_no),\n" +
  580. " manuCode=max(manu_code),\n" +
  581. " supplyCode=max(supply_code)" +
  582. " FROM yp_in_detl WITH(NOLOCK)" +
  583. "<where>" +
  584. " <if test=\"beginDate != null and beginDate != ''\">" +
  585. " and in_date <![CDATA[>=]]> #{beginDate}"+
  586. " </if>"+
  587. " <if test=\"endDate != null and endDate != ''\">" +
  588. " and in_date <![CDATA[<=]]> #{endDate}"+
  589. " </if>"+
  590. " <if test=\"groupNo != null and groupNo != ''\">" +
  591. " AND group_no = #{groupNo}" +
  592. " </if>" +
  593. " GROUP BY charge_code," +
  594. " serial ," +
  595. " manu_code" +
  596. " order by manu_code,sum(buy_amt * buy_price) desc" +
  597. "</where>" +
  598. "</script>")
  599. List<Map<String,Object>> selectDrugManuDetailed(Map map);
  600. /**
  601. * 统计药库入库金额
  602. * @param map
  603. * @return
  604. */
  605. @Select("<script>"+
  606. "select a.group_no as groupNo,\n" +
  607. " left(convert(varchar(12),in_date,111),7) as countDate,\n" +
  608. " sum(round(convert(decimal(18,3),(convert(decimal(18,3),a.buy_price )* a.buy_amt)),2)) as inMoneyBuy,\n" +
  609. " sum(round(convert(decimal(18,3),(convert(decimal(18,3),a.pack_retprice )* a.buy_amt)),2)) as inMoneyRet,\n" +
  610. " outMoneyRet=0\n" +
  611. " from yp_in_detl a WITH(NOLOCK)\n" +
  612. " where in_date <![CDATA[>=]]> #{beginDate} and\n" +
  613. " in_date <![CDATA[<=]]> #{endDate} and\n" +
  614. " a.group_no =#{groupNo}" +
  615. " group by a.group_no,\n" +
  616. " left(convert(varchar(12),in_date,111),7)" +
  617. "</script>")
  618. List<Map<String,Object>> selectDrugInMoneyCount(Map map);
  619. /**
  620. * 按药品分类统计入库金额
  621. * @param map
  622. * @return
  623. */
  624. @Select("<script>"+
  625. "select c.name,sum(b.buy_amt*b.buy_price) inMoneyBuy,sum(b.buy_amt*b.pack_retprice) inMoneyRet from yp_zd_dict a WITH(NOLOCK),yp_in_detl b WITH(NOLOCK),yp_zd_drug_kind c WITH(NOLOCK)\n" +
  626. " where a.code=b.charge_code and a.serial=b.serial and a.drug_kind=c.code\n" +
  627. " and b.in_date<![CDATA[>=]]>#{beginDate} and b.in_date<![CDATA[<=]]>#{endDate} and b.group_no=#{groupNo}\n" +
  628. " group by c.code,c.name" +
  629. "</script>")
  630. List<Map<String,Object>> selectDrugKindInMoneyCount(Map map);
  631. /**
  632. * 按药性分类统计入库金额
  633. * @param map
  634. * @return
  635. */
  636. @Select("<script>"+
  637. "select\n" +
  638. " inMoneyBuy = sum(a.buy_price * a.buy_amt),\n" +
  639. " inMoneyRet = sum(a.pack_retprice * a.buy_amt),\n" +
  640. " outMoneyRet = 0,\n" +
  641. " classCode = c.class_code\n" +
  642. "from yp_in_detl a WITH(NOLOCK),yp_zd_dict c WITH(NOLOCK)\n" +
  643. "where in_date <![CDATA[>=]]>#{beginDate} and\n" +
  644. " in_date <![CDATA[<=]]>#{endDate} and\n" +
  645. " a.group_no=#{groupNo} and\n" +
  646. " a.charge_code=c.code and\n" +
  647. " a.serial=c.serial\n" +
  648. "group by c.class_code" +
  649. "</script>")
  650. List<Map<String,Object>> selectDrugClassInMoneyCount(Map map);
  651. @Select(" select min(eff_date) as effDate from yp_in_detl where charge_code = #{chargeCode} and current_stock >= 1 ")
  652. String selectEffDateByCode(@Param("chargeCode") String chargeCode);
  653. @Select(" select max(eff_date) as effDate from yp_in_detl where charge_code = #{chargeCode} and current_stock = 0 ")
  654. String selectEffDateZeroByCode(@Param("chargeCode") String chargeCode);
  655. }