FinanceInvoiceMapper.xml 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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.dayou.mapper.FinanceInvoiceMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.FinanceInvoice">
  6. <result column="id" property="id" />
  7. <result column="deleted" property="deleted" />
  8. <result column="modified" property="modified" />
  9. <result column="created" property="created" />
  10. <result column="production_fund_id" property="productionFundId" />
  11. <result column="title" property="title" />
  12. <result column="type" property="type" />
  13. <result column="tax_no" property="taxNo" />
  14. <result column="plan_amount" property="planAmount" />
  15. <result column="real_amount" property="realAmount" />
  16. <result column="plan_make_date" property="planMakeDate" />
  17. <result column="real_make_date" property="realMakeDate" />
  18. <result column="state" property="state" />
  19. <result column="reason" property="reason" />
  20. <result column="apply_id" property="applyId" />
  21. <result column="checker_id" property="checkerId" />
  22. <result column="maker_id" property="makerId" />
  23. <result column="bank_name" property="bankName" />
  24. <result column="bank_account" property="bankAccount" />
  25. <result column="bank_address" property="bankAddress" />
  26. <result column="bank_tel" property="bankTel" />
  27. <result column="make_item" property="makeItem" />
  28. <result column="item_quantity" property="itemQuantity" />
  29. <result column="item_unit" property="itemUnit" />
  30. <result column="tax_rate" property="taxRate" />
  31. <result column="tax_amount" property="taxAmount" />
  32. <result column="remark" property="remark" />
  33. </resultMap>
  34. <!-- 通用查询结果列 -->
  35. <sql id="Base_Column_List">
  36. id,
  37. deleted,
  38. modified,
  39. created,
  40. production_fund_id, title, type, tax_no, plan_amount, real_amount, plan_make_date, real_make_date, state, reason, apply_id, checker_id, maker_id, bank_name, bank_account, bank_address, bank_tel, make_item, item_quantity, item_unit, tax_rate, tax_amount, remark
  41. </sql>
  42. <!--开票列表查询Sql-->
  43. <sql id="getPageSql">
  44. SELECT
  45. fi.*,
  46. fi.created AS createTime,
  47. (case orf.business_type when 'ASSET_BUSINESS' THEN '资产业务' WHEN 'MAJOR_BUSINESS' THEN '大中型业务' WHEN 'ITEM_BUSINESS' THEN '土规业务' else '个贷业务' end) as businessType,
  48. orf.order_id,
  49. orf.order_name,
  50. (orf.should_amount=orf.real_amount) as isPayAll,
  51. u.name AS applyName,
  52. pf.production_no
  53. FROM
  54. finance_invoice fi
  55. LEFT JOIN order_fund orf ON fi.order_fund_id = orf.id
  56. LEFT JOIN user u ON u.id = fi.apply_id
  57. left join production_fund pf on pf.id = fi.production_fund_id
  58. where fi.deleted = 0 and orf.deleted = 0
  59. <if test="vo!=null and vo.state!=null and vo.state!='' and vo.state=='审核中' ">
  60. and (fi.state = '申请作废' or fi.state = '审核中')
  61. </if>
  62. <if test="vo!=null and vo.state!=null and vo.state!='' and vo.state!='审核中' ">
  63. and fi.state = #{vo.state}
  64. </if>
  65. <if test="keyword!=null and keyword!='' ">
  66. and (
  67. fi.title like concat ('%',#{keyword},'%')
  68. or orf.order_name like concat('%',#{keyword},'%')
  69. or orf.order_id like concat('%',#{keyword},'%')
  70. or orf.business_type like concat('%',#{keyword},'%')
  71. or u.name like concat('%',#{keyword},'%')
  72. or fi.type like concat('%',#{keyword},'%')
  73. or fi.tax_no like concat('%',#{keyword},'%')
  74. or fi.plan_amount like concat('%',#{keyword},'%')
  75. or fi.state like concat('%',#{keyword},'%')
  76. or fi.remark like concat('%',#{keyword},'%')
  77. or pf.production_no like concat('%',#{keyword},'%')
  78. )
  79. </if>
  80. <if test="vo!=null and vo.pStartDate!=null and vo.pStartDate!=''">
  81. and fi.plan_make_date &gt;= #{vo.pStartDate}
  82. </if>
  83. <if test="vo!=null and vo.pEndDate!=null and vo.pEndDate!=''">
  84. and fi.plan_make_date &lt;= #{vo.pEndDate}
  85. </if>
  86. <if test="vo!=null and vo.rStartDate!=null and vo.rStartDate!=''">
  87. and fi.real_make_date &gt;= #{vo.rStartDate}
  88. </if>
  89. <if test="vo!=null and vo.rEndDate!=null and vo.rEndDate!=''">
  90. and fi.real_make_date &lt;= #{vo.rEndDate}
  91. </if>
  92. <if test="vo!=null and vo.dStartDate!=null and vo.dStartDate!=''">
  93. and fi.modified &gt;= #{vo.dStartDate}
  94. </if>
  95. <if test="vo!=null and vo.dEndDate!=null and vo.dEndDate!=''">
  96. and fi.modified &lt;= #{vo.dEndDate}
  97. </if>
  98. <if test="vo!=null and vo.aStartDate!=null and vo.aStartDate!=''">
  99. and fi.created &gt;= #{vo.aStartDate}
  100. </if>
  101. <if test="vo!=null and vo.aEndDate!=null and vo.aEndDate!=''">
  102. and fi.created &lt;= #{vo.aEndDate}
  103. </if>
  104. <if test="vo!=null and vo.state!=null and vo.state!='' and vo.state!='审核中' ">
  105. order by fi.modified DESC
  106. </if>
  107. <if test="vo!=null and vo.state!=null and vo.state!='' and vo.state=='审核中' ">
  108. order by fi.created DESC
  109. </if>
  110. </sql>
  111. <!--开票分页查询-->
  112. <select id="getPage" parameterType="com.dayou.entity.FinanceInvoice" resultType="com.dayou.vo.FinanceInvoiceVo">
  113. <include refid="getPageSql" />
  114. </select>
  115. <!--开票信息导出-->
  116. <select id="exportPage" resultType="com.dayou.vo.FinanceInvoiceVo">
  117. <include refid="getPageSql" />
  118. </select>
  119. <select id="getInvoiceAmountInfo" parameterType="com.dayou.dto.MajorProductionSimpleDTO" resultType="com.dayou.vo.FinanceInvoiceVo">
  120. SELECT
  121. pf.*,
  122. orderFund.*,
  123. invoice.*
  124. FROM
  125. (
  126. SELECT
  127. id,
  128. business_type,
  129. real_amount AS orderRealAmount,
  130. should_amount
  131. FROM
  132. order_fund
  133. WHERE
  134. deleted = 0
  135. AND business_type = 'MAJOR_BUSINESS'
  136. AND business_id = #{dto.majorId}) orderFund
  137. LEFT JOIN (
  138. SELECT
  139. order_fund_id,
  140. bank_name,
  141. real_amount AS invoiceAmount,
  142. title AS invoiceTitle,
  143. type AS invoiceType,
  144. tax_no,
  145. tax_amount AS invoiceTaxAmount,
  146. tax_rate AS invoiceTaxRate,
  147. state AS invoiceState,
  148. real_make_date AS invoiceDate
  149. FROM
  150. finance_invoice
  151. WHERE
  152. state != '驳回'
  153. AND state != '作废'
  154. AND deleted = 0
  155. ) invoice ON invoice.order_fund_id = orderFund.id
  156. LEFT JOIN (
  157. SELECT
  158. mp.id,
  159. p.real_amount AS prodRealAmount,
  160. mp.standard_amount,
  161. p.order_fund_id,
  162. p.business_type,
  163. mp.report_no as productionNo,
  164. ( CASE mp.production WHEN 'STATEMENT' THEN '价值意见书' WHEN 'REPORT' THEN '报告' ELSE '复评函' END ) AS productionType
  165. FROM
  166. major_production mp
  167. left JOIN production_fund p ON ( mp.report_no = ifnull(p.production_no,mp.report_no) AND mp.major_id = ifnull(p.business_id,mp.major_id ))
  168. WHERE
  169. mp.deleted = 0
  170. AND mp.major_id = #{dto.majorId}
  171. <if test="dto.productionNos!=null and dto.productionNos.size()>0">
  172. and mp.report_no in (
  173. <foreach collection="dto.productionNos" separator="," index="index" item="item">
  174. #{item}
  175. </foreach>
  176. )
  177. </if>
  178. ) pf on ( orderFund.id = ifnull(pf.order_fund_id,orderFund.id) AND orderFund.business_type = ifnull(pf.business_type,orderFund.business_type) )
  179. order by pf.id asc
  180. </select>
  181. <select id="getInvoiceAmountInfoEmptyProduction" parameterType="com.dayou.dto.MajorProductionSimpleDTO" resultType="com.dayou.vo.FinanceInvoiceVo">
  182. SELECT
  183. orderFund.*,
  184. invoice.*
  185. FROM
  186. (
  187. SELECT
  188. id,
  189. business_type,
  190. real_amount AS orderRealAmount,
  191. should_amount
  192. FROM
  193. order_fund
  194. WHERE
  195. deleted = 0
  196. AND business_type = 'MAJOR_BUSINESS'
  197. AND business_id = #{dto.majorId}) orderFund
  198. LEFT JOIN (
  199. SELECT
  200. order_fund_id,
  201. bank_name,
  202. real_amount AS invoiceAmount,
  203. title AS invoiceTitle,
  204. type AS invoiceType,
  205. tax_no,
  206. tax_amount AS invoiceTaxAmount,
  207. tax_rate AS invoiceTaxRate,
  208. state AS invoiceState,
  209. real_make_date AS invoiceDate
  210. FROM
  211. finance_invoice
  212. WHERE
  213. state != '驳回'
  214. AND state != '作废'
  215. AND deleted = 0
  216. ) invoice ON invoice.order_fund_id = orderFund.id
  217. </select>
  218. <!--根据收款信息获取发票号-->
  219. <select id="getInvoiceNoByFundId" resultType="java.lang.String">
  220. SELECT GROUP_CONCAT(ticket_no SEPARATOR ',')
  221. FROM finance_invoice
  222. WHERE finance_invoice.deleted = 0
  223. AND finance_invoice.order_fund_id = #{orderFundId}
  224. <if test="productionFundId != null">
  225. AND finance_invoice.production_fund_id = #{productionFundId}
  226. </if>
  227. </select>
  228. <select id="getList" resultType="com.dayou.entity.FinanceInvoice">
  229. select * from finance_invoice where deleted = 0 and order_fund_id = #{orderFundId}
  230. <if test="productionFundId!=null">
  231. and production_fund_id = #{productionFundId}
  232. </if>
  233. <if test="productionFundId == null">
  234. and production_fund_id is null
  235. </if>
  236. order by created DESC
  237. </select>
  238. </mapper>