MajorProductionMapper.xml 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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.MajorProductionMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.dayou.entity.MajorProduction">
  6. <result column="id" property="id" />
  7. <result column="major_id" property="majorId" />
  8. <result column="deleted" property="deleted" />
  9. <result column="created" property="created" />
  10. <result column="modified" property="modified" />
  11. <result column="report_no" property="reportNo" />
  12. <result column="production" property="production" />
  13. <result column="signatory" property="signatory" />
  14. <result column="name" property="name" />
  15. <result column="client_name" property="clientName" />
  16. <result column="client_tel" property="clientTel" />
  17. <result column="client_address" property="clientAddress" />
  18. <result column="owner" property="owner" />
  19. <result column="value_timing" property="valueTiming" />
  20. <result column="evaluate_acreage" property="evaluateAcreage" />
  21. <result column="evaluate_amount" property="evaluateAmount" />
  22. <result column="evaluate_price" property="evaluatePrice" />
  23. <result column="comment" property="comment" />
  24. <result column="qr_code" property="qrCode" />
  25. <result column="repertory_state" property="repertoryState" />
  26. <result column="first_check" property="firstCheck" />
  27. <result column="second_check" property="secondCheck" />
  28. <result column="third_check" property="thirdCheck" />
  29. <result column="save_file_check" property="saveFileCheck" />
  30. <result column="save_file_second_check" property="saveFileSecondCheck" />
  31. <result column="if_save_file" property="ifSaveFile" />
  32. </resultMap>
  33. <!-- 通用查询结果列 -->
  34. <sql id="Base_Column_List">
  35. id,
  36. major_id,
  37. deleted,
  38. created,
  39. modified,
  40. report_no, production,signatory, name, client_name, client_tel, client_address, owner, value_timing, evaluate_acreage, evaluate_amount, evaluate_price
  41. , comment,qr_code,repertory_state,first_check,second_check,third_check,save_file_check,save_file_second_check,if_save_file
  42. </sql>
  43. <select id="getList" parameterType="com.dayou.entity.MajorProduction" resultType="com.dayou.entity.MajorProduction">
  44. select * from (
  45. SELECT
  46. mp.id,
  47. mp.major_id,
  48. (SELECT id FROM work_flow_node_instance
  49. WHERE business_id = #{production.majorId}
  50. AND (business_sub_id = mp.report_no or business_min_id = mp.report_no ) and deleted = 0
  51. and sequence = ( #{production.sequence} + 1) ) AS nextInstanceNodeId ,
  52. mp.report_no,
  53. mp.production,
  54. mp.signatory,
  55. mp.`name`,
  56. mp.client_name,
  57. mp.client_tel,
  58. mp.client_address,
  59. mp.`owner`,
  60. mp.value_timing,
  61. mp.evaluate_acreage,
  62. (mp.evaluate_amount/10000) as evaluateAmount,
  63. mp.evaluate_price,
  64. mp.`comment`,
  65. mp.qr_code,
  66. mp.repertory_state,
  67. mp.first_check,
  68. mp.second_check,
  69. mp.third_check,
  70. mp.save_file_check,
  71. mp.save_file_second_check,
  72. mp.if_save_file,
  73. mp.file_path,
  74. m.`name` AS majorName,
  75. mp.checked_file_path,
  76. mp.validate_code,
  77. mp.is_submit,
  78. mp.is_record,
  79. mp.main_worker,
  80. mp.main_worker_no,
  81. mp.minor_worker,
  82. mp.minor_worker_no,
  83. mp.small_worker,
  84. mp.small_worker_no,
  85. mp.work_start_date,
  86. mp.work_end_date,
  87. mp.work_purpose,
  88. mp.not_record_reason,
  89. mp.not_submit_reason
  90. FROM
  91. major_production mp
  92. LEFT JOIN major m ON m.id = mp.major_id
  93. WHERE
  94. mp.major_id = #{production.majorId}
  95. <if test="production!=null and production.afterProduction==null
  96. and production.statementNo==null and production.reportNo!=null and production.reportNo!='' ">
  97. and mp.report_no = #{production.reportNo}
  98. </if>
  99. <if test="production!=null and production.afterProduction==null
  100. and production.statementNo!=null and production.statementNo!='' and production.reportNo==null ">
  101. and mp.report_no = #{production.statementNo}
  102. </if>
  103. <if test="production!=null and production.afterProduction!=null and production.afterProduction=='REPORT' and production.reportNo!=null and production.reportNo!='' ">
  104. and mp.report_no in (select report_no from major_target where major_id = #{production.majorId} and statement_no =#{production.reportNo} and deleted = 0)
  105. </if>
  106. <if test="production!=null and production.afterProduction!=null and production.afterProduction=='LETTER' and production.reportNo!=null and production.reportNo!='' ">
  107. and mp.report_no in (select letter_no from major_target where major_id = #{production.majorId} and statement_no =#{production.reportNo} and deleted = 0)
  108. </if>
  109. <if test="production!=null and production.production!=null and production.production!='' ">
  110. and mp.production = #{production.production}
  111. </if>
  112. <if test="production!=null and production.afterProduction==null and production.statementNo!=null
  113. and production.statementNo!='' and production.reportNo!=null and production.reportNo!=''">
  114. and mp.report_no in (#{production.statementNo},#{production.reportNo})
  115. </if>
  116. and mp.deleted = 0 and m.deleted = 0
  117. order by mp.created ASC ) t where nextInstanceNodeId is null
  118. </select>
  119. <select id="getPendingList" parameterType="com.dayou.entity.MajorProduction" resultType="com.dayou.entity.MajorProduction">
  120. SELECT
  121. mp.id,
  122. mp.major_id,
  123. mp.report_no,
  124. mp.production,
  125. mp.signatory,
  126. mp.`name`,
  127. mp.client_name,
  128. mp.client_tel,
  129. mp.client_address,
  130. mp.`owner`,
  131. mp.value_timing,
  132. mp.evaluate_acreage,
  133. (mp.evaluate_amount/10000) as evaluateAmount,
  134. mp.evaluate_price,
  135. mp.`comment`,
  136. mp.qr_code,
  137. mp.repertory_state,
  138. mp.first_check,
  139. mp.second_check,
  140. mp.third_check,
  141. mp.save_file_check,
  142. mp.save_file_second_check,
  143. mp.if_save_file,
  144. mp.file_path,
  145. m.`name` AS majorName,
  146. mp.checked_file_path,
  147. mp.validate_code,
  148. mp.is_submit,
  149. mp.is_record,
  150. mp.main_worker,
  151. mp.main_worker_no,
  152. mp.minor_worker,
  153. mp.minor_worker_no,
  154. mp.small_worker,
  155. mp.small_worker_no,
  156. mp.work_start_date,
  157. mp.work_end_date,
  158. mp.work_purpose
  159. FROM
  160. major_production mp
  161. LEFT JOIN major m ON m.id = mp.major_id
  162. WHERE
  163. mp.major_id = #{production.majorId}
  164. <if test="production!=null and production.afterProduction==null
  165. and production.statementNo==null and production.reportNo!=null and production.reportNo!='' ">
  166. and mp.report_no = #{production.reportNo}
  167. </if>
  168. <if test="production!=null and production.afterProduction==null
  169. and production.statementNo!=null and production.statementNo!='' and production.reportNo==null ">
  170. and mp.report_no = #{production.statementNo}
  171. </if>
  172. <if test="production!=null and production.afterProduction==null and production.statementNo!=null
  173. and production.statementNo!='' and production.reportNo!=null and production.reportNo!=''">
  174. and mp.report_no in (#{production.statementNo},#{production.reportNo})
  175. </if>
  176. and mp.deleted = 0 and m.deleted = 0
  177. order by mp.created ASC
  178. </select>
  179. <select id="saveDonePage" parameterType="com.dayou.vo.MajorProductionSaveDoneVO" resultType="com.dayou.vo.MajorProductionSaveDoneVO">
  180. SELECT
  181. mp.id,
  182. mp.name,
  183. mp.major_id,
  184. mp.report_no,
  185. m.order_id,
  186. m.name as orderName,
  187. u1.name as clientManager,
  188. u2.name as principal,
  189. m.business_object_type,
  190. mp.production,
  191. mp.repertory_state,
  192. mp.save_file_date,
  193. pf.real_amount
  194. FROM
  195. major_production mp
  196. LEFT JOIN major m ON m.id = mp.major_id
  197. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  198. LEFT JOIN user u2 ON u2.id = m.principal_id
  199. left join (select business_id,production_no,real_amount, production_type from production_fund where business_type='MAJOR_BUSINESS' and deleted = 0) pf
  200. on (pf.business_id = mp.major_id and pf.production_no =mp.report_no and mp.production = pf.production_type)
  201. where mp.deleted = 0 and m.deleted = 0 and mp.if_save_file= 1
  202. <if test="keyword!=null and keyword!='' ">
  203. and (
  204. mp.name like concat('%',#{keyword},'%')
  205. or m.order_id like concat('%',#{keyword},'%')
  206. or m.name like concat('%',#{keyword},'%')
  207. or u1.NAME like concat('%',#{keyword},'%')
  208. or u2.NAME like concat('%',#{keyword},'%')
  209. or mp.report_no like concat('%',#{keyword},'%')
  210. )
  211. </if>
  212. <if test="done!=null and done.production!=null and done.production!=''">
  213. and mp.production =#{done.production}
  214. </if>
  215. <if test="done!=null and done.startDate!=null and done.startDate!=''">
  216. and mp.save_file_date &gt;= #{done.startDate}
  217. </if>
  218. <if test="done!=null and done.endDate!=null and done.endDate!=''">
  219. and mp.save_file_date &lt;= #{done.endDate}
  220. </if>
  221. <if test="done!=null and done.hasCommission == true">
  222. and pf.real_amount > 0
  223. </if>
  224. <if test="done!=null and done.hasCommission == false">
  225. and (pf.real_amount IS NULL OR pf.real_amount = 0)
  226. </if>
  227. order by mp.save_file_date desc
  228. </select>
  229. <select id="getHouse" parameterType="com.dayou.vo.MajorProductionVO" resultType="com.dayou.vo.MajorProductionVO">
  230. select
  231. (@i := @i + 1) AS id,
  232. temp.* from (SELECT
  233. '大中型' AS businessType,
  234. mp.report_no AS reportNo,
  235. ( CASE mp.production WHEN 'STATEMENT' THEN '价值意见书' WHEN 'REPORT' THEN '报告' ELSE '复评函' END ) production,
  236. mp.repertory_state,
  237. mp.repertory_in_time,
  238. u.name as clientManager
  239. FROM
  240. major_production mp left join major m on m.id = mp.major_id
  241. left join user u on u.id = m.client_manager_id
  242. WHERE
  243. mp.deleted = 0
  244. AND mp.repertory_state = 0 UNION ALL
  245. SELECT
  246. '资产' AS business_type,
  247. ap.production_no AS reportNo,
  248. ( CASE ap.production_type WHEN 'STATEMENT' THEN '价值意见书' WHEN 'REPORT' THEN '报告' WHEN 'CONSULT' THEN '咨询报告' WHEN 'TECHNIC' THEN '技术报告' WHEN 'FINAL' THEN '结果报告' ELSE '复评函' END ) production,
  249. ap.repertory_state,
  250. ap.repertory_in_time,
  251. u.name as clientManager
  252. FROM
  253. assets_production ap left join assets a on a.id = ap.business_id
  254. left join user u on u.id = a.client_manager_id
  255. WHERE
  256. ap.deleted = 0
  257. AND ap.repertory_state = 0 UNION ALL
  258. SELECT
  259. '个贷' AS business_type,
  260. p.order_id AS reportNo,
  261. ( CASE pp.production WHEN 'STATEMENT' THEN '价值意见书' WHEN 'REPORT' THEN '报告' WHEN 'CONSULT' THEN '咨询报告' WHEN 'TECHNIC' THEN '技术报告' WHEN 'FINAL' THEN '结果报告' ELSE '复评函' END ) production,
  262. pp.repertory_state,
  263. pp.repertory_in_time,
  264. u.name as clientManager
  265. FROM
  266. personal_production pp
  267. LEFT JOIN personal_target pt ON pt.id = pp.target_id
  268. LEFT JOIN personal p ON p.id = pt.personal_id
  269. left join user u on u.id = p.client_manager_id
  270. WHERE
  271. p.deleted = 0
  272. AND pp.repertory_state = 0
  273. AND pt.deleted = 0
  274. AND pp.deleted = 0) temp
  275. <where>
  276. <if test="vo!=null and vo.reportNo!=null and vo.reportNo!=''">
  277. and temp.reportNo =#{vo.reportNo}
  278. </if>
  279. <if test="vo!=null and vo.production!=null and vo.production!=''">
  280. and temp.production =#{vo.production}
  281. </if>
  282. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  283. and temp.repertory_in_time &gt;= #{vo.startDate}
  284. </if>
  285. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  286. and temp.repertory_in_time &lt;= #{vo.endDate}
  287. </if>
  288. </where>
  289. order by temp.repertory_in_time desc
  290. </select>
  291. <resultMap id="myOrderMap" type="com.dayou.vo.MajorOrderVO">
  292. <result column="id" property="id" />
  293. <result column="businessId" property="businessId" />
  294. <result column="order_id" property="orderId" />
  295. <result column="orderName" property="orderName" />
  296. <result column="production" property="production" />
  297. <result column="productionNo" property="productionNo" />
  298. <result column="evaluate_amount" property="evaluateAmount" />
  299. <result column="if_save_file" property="ifSaveFile" />
  300. <result column="principal" property="principal" />
  301. <result column="clientManager" property="clientManager" />
  302. <result column="clienteleName" property="clienteleName" />
  303. <result column="clienteleSubName" property="clienteleSubName" />
  304. <result column="bailor" property="bailor" />
  305. <result column="clienteleContactName" property="clienteleContactName" />
  306. <result column="owner" property="owner" />
  307. <result column="orderFundId" property="orderFundId" />
  308. <result column="should_amount" property="shouldAmount" />
  309. <result column="real_amount" property="realAmount" />
  310. <result column="shouldAmount" property="shouldAmount" />
  311. <result column="orderShouldAmount" property="orderShouldAmount" />
  312. <result column="orderRealAmount" property="orderRealAmount" />
  313. <result column="productionFundId" property="productionFundId" />
  314. <result column="created" property="created" />
  315. <result column="remark" property="remark" />
  316. <result column="invoiceAmount" property="invoiceAmount" />
  317. <result column="delivery" property="delivery" />
  318. <result column="mDeclareResult" property="mDeclareResult" />
  319. <result column="eDeclareResult" property="eDeclareResult" />
  320. <association property="currentNodeName" javaType="java.lang.String"
  321. select="queryCurrentNodeName" column="{businessId=businessId,productionNo=productionNo}"/>
  322. </resultMap>
  323. <select id="queryCurrentNodeName" resultType="java.lang.String">
  324. select name from work_node where id = (
  325. select node_id from work_flow_node_instance where
  326. business_type='MAJOR_BUSINESS'
  327. and state= 'PENDING'
  328. AND deleted = 0
  329. and business_id = #{businessId}
  330. <if test="productionNo!=null and productionNo!=''">
  331. and (business_min_id = #{productionNo} or business_sub_id = #{productionNo}) order by id desc limit 1
  332. </if>
  333. <if test="productionNo==null">
  334. and business_sub_id is null and business_min_id is null
  335. </if>
  336. )
  337. </select>
  338. <sql id="myMajorOrder">
  339. SELECT
  340. mp.id AS id,
  341. m.id as businessId,
  342. m.order_id,
  343. IF(mp.name IS NULL, m.name, mp.name) AS orderName,
  344. mp.report_no as productionNo,
  345. mp.production,
  346. mp.if_save_file,
  347. mp.evaluate_amount,
  348. u.name as principal,
  349. u1.name as clientManager,
  350. cc.name as clienteleName,
  351. cc1.name as clienteleSubName,
  352. cl.name as clienteleContactName,
  353. m.bailor,
  354. m.owner,
  355. m.created,
  356. orf.id as orderFundId,
  357. orf.should_amount as orderShouldAmount,
  358. orf.real_amount as orderRealAmount,
  359. pf.remark,
  360. pf.id as productionFundId,
  361. pf.real_amount,
  362. pf.production_should_amount as shouldAmount,
  363. fi.invoiceAmount,
  364. mp.delivery,
  365. ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) as mDeclareResult,
  366. ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) as eDeclareResult
  367. FROM
  368. major m
  369. left join (select id,name,major_id,report_no,evaluate_amount,production,if_save_file,delivery from major_production where deleted = 0 ) mp on mp.major_id = m.id
  370. left join user u on u.id = m.principal_id
  371. left join user u1 on u1.id = m.client_manager_id
  372. left join customer_company cc on cc.id = m.clientele_id
  373. left join customer_company cc1 on cc1.id = m.clientele_sub_id
  374. left join customer_linkman cl on cl.id = m.clientele_contact_id
  375. left join (select * from order_fund where business_type ='MAJOR_BUSINESS' and deleted = 0) orf on orf.business_id = m.id
  376. left join (select * from production_fund where business_type = 'MAJOR_BUSINESS' and deleted = 0) pf on (pf.business_id = m.id and pf.production_no = mp.report_no and mp.production = pf.production_type)
  377. left join (select sum(real_amount) as invoiceAmount,order_fund_id,production_fund_id from finance_invoice where state='已开票' and deleted = 0 group by production_fund_id) fi on (fi.order_fund_id = orf.id and fi.production_fund_id = pf.id)
  378. </sql>
  379. <sql id="myOrderSql">
  380. <include refid="myMajorOrder" />
  381. where m.deleted = 0
  382. and m.client_manager_id = #{vo.clientManagerId}
  383. <if test="keyword!=null and keyword!='' ">
  384. and (
  385. m.name like concat ('%',#{keyword},'%')
  386. or m.order_id like concat('%',#{keyword},'%')
  387. or u.name like concat('%',#{keyword},'%')
  388. or u1.name like concat('%',#{keyword},'%')
  389. or cc.name like concat('%',#{keyword},'%')
  390. or cc1.name like concat('%',#{keyword},'%')
  391. or cl.name like concat('%',#{keyword},'%')
  392. or m.bailor like concat('%',#{keyword},'%')
  393. or m.owner like concat('%',#{keyword},'%')
  394. or orf.should_amount like concat('%',#{keyword},'%')
  395. or orf.real_amount like concat('%',#{keyword},'%')
  396. or orf.remark like concat('%',#{keyword},'%')
  397. or mp.report_no like concat('%',#{keyword},'%')
  398. )
  399. </if>
  400. <if test="vo!=null and vo.principalId!=null and vo.principalId!=''">
  401. AND m.principal_id like concat('%',#{vo.principalId},'%')
  402. </if>
  403. <if test="vo!=null and vo.orderId!=null and vo.orderId!=''">
  404. AND m.order_id like concat('%',#{vo.orderId},'%')
  405. </if>
  406. <if test="vo!=null and vo.productionNo!=null and vo.productionNo!=''">
  407. AND mp.report_no like concat('%',#{vo.productionNo},'%')
  408. </if>
  409. <if test="vo!=null and vo.clienteleName!=null and vo.clienteleName!=''">
  410. AND cc.name like concat('%',#{vo.clienteleName},'%')
  411. </if>
  412. <if test="vo!=null and vo.clienteleSubName!=null and vo.clienteleSubName!=''">
  413. AND cc1.name like concat('%',#{vo.clienteleSubName},'%')
  414. </if>
  415. <if test="vo!=null and vo.startDate!=null and vo.startDate!=''">
  416. and m.created &gt;= #{vo.startDate}
  417. </if>
  418. <if test="vo!=null and vo.endDate!=null and vo.endDate!=''">
  419. and m.created &lt;= #{vo.endDate}
  420. </if>
  421. <if test="vo!=null and vo.production!=null and vo.production!='ORDER'">
  422. AND mp.production = #{vo.production}
  423. </if>
  424. <if test="vo!=null and vo.production!=null and vo.production=='ORDER'">
  425. AND mp.id is null
  426. </if>
  427. <if test="vo!=null and vo.delivery == true">
  428. AND mp.delivery = #{vo.delivery}
  429. </if>
  430. <if test="vo!=null and vo.delivery == false">
  431. AND (mp.delivery = #{vo.delivery} OR mp.delivery IS NULL)
  432. </if>
  433. <if test="vo!=null and vo.hasRealAmount == true">
  434. AND (pf.real_amount IS NOT NULL OR pf.real_amount > 0)
  435. </if>
  436. <if test="vo!=null and vo.hasRealAmount == false">
  437. AND (pf.real_amount IS NULL OR pf.real_amount = 0)
  438. </if>
  439. <if test="vo!=null and vo.hasShouldAmount == true">
  440. AND (orf.should_amount IS NOT NULL OR orf.should_amount > 0 OR pf.production_should_amount IS NOT NULL OR pf.production_should_amount > 0)
  441. </if>
  442. <if test="vo!=null and vo.hasShouldAmount == false">
  443. AND (orf.should_amount IS NULL OR orf.should_amount = 0)
  444. AND (pf.production_should_amount IS NULL OR pf.production_should_amount = 0)
  445. </if>
  446. order by m.created DESC
  447. </sql>
  448. <select id="myOrder" parameterType="com.dayou.vo.MajorOrderVO" resultMap="myOrderMap">
  449. <include refid="myOrderSql" />
  450. </select>
  451. <select id="exportMyOrder" resultType="com.dayou.vo.MajorOrderVO">
  452. <include refid="myOrderSql" />
  453. </select>
  454. <select id="waitingClaim" parameterType="com.dayou.vo.MajorOrderVO" resultType="com.dayou.vo.MajorOrderVO">
  455. <include refid="myMajorOrder" />
  456. where m.deleted = 0
  457. and m.client_manager_id = #{vo.clientManagerId} and orf.id is not null
  458. <if test="vo!=null and vo.name!=null and vo.name !=''">
  459. and m.name like concat ('%',#{vo.name},'%')
  460. </if>
  461. <if test="vo!=null and vo.orderId!=null and vo.orderId !=''">
  462. and m.order_id like concat ('%',#{vo.orderId},'%')
  463. </if>
  464. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='审核通过'">
  465. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) = '审核通过'
  466. </if>
  467. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='审核拒绝'">
  468. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) = '审核拒绝'
  469. </if>
  470. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='审核中'">
  471. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) = '审核中'
  472. </if>
  473. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='未申报'">
  474. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) is null
  475. </if>
  476. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='审核通过'">
  477. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) = '审核通过'
  478. </if>
  479. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='审核拒绝'">
  480. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) = '审核拒绝'
  481. </if>
  482. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='审核中'">
  483. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) = '审核中'
  484. </if>
  485. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='未申报'">
  486. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id IS NULL AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) is null
  487. </if>
  488. order by m.created DESC
  489. </select>
  490. <select id="getMajorProductionAboutFundId" parameterType="java.lang.Long" resultType="com.dayou.entity.MajorProduction">
  491. SELECT
  492. mp.id,
  493. pf.id AS productionFundId,
  494. sum(pf.real_amount) as realAmount,
  495. mp.production,
  496. mp.NAME,
  497. mp.client_name,
  498. mp.OWNER,
  499. mp.evaluate_acreage,
  500. mp.evaluate_amount,
  501. mp.evaluate_price,
  502. mp.report_no,
  503. mp.repertory_state,
  504. mp.repertory_in_time,
  505. mp.repertory_out_time,
  506. mp.if_save_file,
  507. mp.save_file_date,
  508. mp.delivery,
  509. `of`.should_amount AS orderShouldAmount,
  510. pf.production_should_amount as shouldAmount,
  511. m.order_id,
  512. m.name as orderName,
  513. m.id as businessId,
  514. `of`.id as orderFundId
  515. FROM
  516. major_production mp
  517. left join major m on m.id =mp.major_id
  518. LEFT JOIN ( SELECT id, business_id, production_no, real_amount, production_type,production_should_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf ON ( mp.major_id = pf.business_id AND mp.report_no = pf.production_no AND mp.production = pf.production_type )
  519. LEFT JOIN (SELECT id,business_id,should_amount FROM order_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0) AS `of` ON mp.major_id = `of`.business_id
  520. WHERE
  521. mp.major_id = #{majorId} and mp.deleted = 0
  522. AND mp.NAME IS NOT NULL
  523. GROUP BY mp.id
  524. ORDER BY mp.id DESC
  525. </select>
  526. <select id="todoSaveFilePage" parameterType="com.dayou.vo.TaskTodoVO" resultType="com.dayou.vo.TaskTodoVO">
  527. SELECT
  528. wfni.id,
  529. mp.id AS productionId,
  530. mp.NAME,
  531. mp.repertory_state,
  532. wtr.id AS taskId,
  533. wfni.id AS currentNodeId,
  534. wfni.business_min_id,
  535. wfni.business_sub_id,
  536. mp.report_no,
  537. wfni.business_id,
  538. m.NAME AS orderName,
  539. m.order_id,
  540. u1.NAME AS clientManager,
  541. u2.NAME AS principal,
  542. d.NAME AS departmentName,
  543. wfni.NAME AS nodeName,
  544. wfni.CODE AS nodeCode,
  545. u.NAME AS HANDLER,
  546. pf.real_amount AS realAmount,
  547. wtr.handler_id,
  548. wtr.finished AS taskFinished,
  549. DATE_FORMAT( m.created, '%Y-%m-%d' ) AS created,
  550. wtr.created AS taskCreated,
  551. mp.production
  552. FROM
  553. work_task_record wtr
  554. LEFT JOIN work_node_task wnt ON wnt.id = wtr.task_id
  555. INNER JOIN (
  556. SELECT
  557. wn.NAME,
  558. wn.CODE,
  559. wfni.id,
  560. wfni.business_id,
  561. wfni.business_sub_id,
  562. wfni.business_min_id,
  563. wfni.state
  564. FROM
  565. work_flow_node_instance wfni
  566. LEFT JOIN work_node wn ON wn.id = wfni.node_id
  567. WHERE
  568. wfni.business_type = 'MAJOR_BUSINESS'
  569. AND wfni.state = 'PENDING'
  570. AND wfni.deleted = 0
  571. AND wn.deleted = 0
  572. AND wn.CODE = 'BUSINESS_ARCHIVING'
  573. ) wfni ON wtr.instance_id = wfni.id
  574. LEFT JOIN major m ON m.id = wfni.business_id
  575. LEFT JOIN user u ON u.id = wtr.handler_id
  576. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  577. LEFT JOIN user u2 ON u2.id = m.principal_id
  578. LEFT JOIN department d ON d.id = m.department_id
  579. LEFT JOIN ( SELECT id, major_id, report_no, NAME, repertory_state, production FROM major_production WHERE deleted = 0 ) mp
  580. ON ( mp.major_id = m.id AND (mp.report_no = wfni.business_sub_id or mp.report_no = wfni.business_min_id))
  581. LEFT JOIN ( SELECT business_id, production_no, real_amount FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) pf
  582. ON ( pf.business_id = m.id AND pf.production_no = mp.report_no )
  583. WHERE u.deleted = 0
  584. and wtr.handler_id =#{todoVO.handlerId}
  585. AND wnt.deleted = 0
  586. AND wtr.deleted = 0
  587. <if test="keyword!=null and keyword!='' ">
  588. and (
  589. mp.name like concat('%',#{keyword},'%')
  590. or m.order_id like concat('%',#{keyword},'%')
  591. or m.name like concat('%',#{keyword},'%')
  592. or wfni.business_min_id like concat('%',#{keyword},'%')
  593. or u1.NAME like concat('%',#{keyword},'%')
  594. or u2.NAME like concat('%',#{keyword},'%')
  595. )
  596. </if>
  597. <if test="todoVO!=null and todoVO.production!=null and todoVO.production!=''">
  598. and mp.production =#{todoVO.production}
  599. </if>
  600. ORDER BY
  601. mp.report_no ASC
  602. </select>
  603. <update id="updateSaveFileInfo" parameterType="java.util.List">
  604. update major_production set if_save_file = 1 ,save_file_date= now() where id in (
  605. <foreach collection="productionIds" index="index" item="item" separator=",">
  606. #{item}
  607. </foreach>
  608. )
  609. </update>
  610. <select id="performanceAllotPage" parameterType="com.dayou.vo.MajorProductionPerformanceVO" resultType="com.dayou.vo.MajorProductionPerformanceVO">
  611. SELECT
  612. mp.id,
  613. m.order_id,
  614. m.id as majorId,
  615. mp.NAME,
  616. mp.report_no,
  617. (case mp.production when 'REPORT' then '报告' when 'STATEMENT' THEN '价值意见书' else '复评函' end ) as production,
  618. pf.real_amount AS claimAmount,
  619. allot.major_production_id AS isAllot
  620. FROM
  621. major_production mp
  622. left join (select business_id,production_no,production_type,real_amount from production_fund where business_type = 'MAJOR_BUSINESS' and deleted = 0 ) pf on (mp.major_id = pf.business_id and mp.report_no = pf.production_no and mp.production = pf.production_type)
  623. LEFT JOIN major m ON m.id = mp.major_id
  624. LEFT JOIN (SELECT major_production_id FROM major_production_allot WHERE deleted = 0 and user_type = 'EVALUATE' GROUP BY major_production_id) AS allot ON major_production_id = mp.id
  625. WHERE
  626. m.deleted = 0
  627. AND mp.deleted = 0
  628. AND mp.NAME IS NOT NULL
  629. and m.department_id in (
  630. <foreach collection="vo.departmentIds" open="(" close=")" separator="," item="departmentId">
  631. #{departmentId}
  632. </foreach>
  633. )
  634. <if test="keyword!=null and keyword!='' ">
  635. and (
  636. mp.name like concat('%',#{keyword},'%')
  637. or m.order_id like concat('%',#{keyword},'%')
  638. or mp.report_no like concat('%',#{keyword},'%')
  639. )
  640. </if>
  641. <if test="vo!=null and vo.production != null">
  642. AND mp.production = #{vo.production}
  643. </if>
  644. <if test="vo!=null and vo.hasRealAmount == true">
  645. AND (pf.real_amount IS NOT NULL OR pf.real_amount > 0)
  646. </if>
  647. <if test="vo!=null and vo.hasRealAmount == false">
  648. AND (pf.real_amount IS NULL OR pf.real_amount = 0)
  649. </if>
  650. <if test="vo!=null and vo.hasAllot == true">
  651. AND allot.major_production_id IS NOT NULL
  652. </if>
  653. <if test="vo!=null and vo.hasAllot == false">
  654. AND allot.major_production_id IS NULL
  655. </if>
  656. order by mp.id DESC, isAllot ASC
  657. </select>
  658. <select id="validateProd" parameterType="java.lang.Long" resultType="com.dayou.vo.ProdValidateVO">
  659. SELECT
  660. mp.evaluate_acreage as acreage,
  661. ROUND(mp.evaluate_amount/10000,2) as amount,
  662. mp.name AS productionName,
  663. mp.report_no AS productionNo ,
  664. mp.client_name as bailor
  665. FROM
  666. major_production mp
  667. WHERE
  668. mp.id = #{id}
  669. AND mp.deleted = 0
  670. </select>
  671. <select id="waitingClaimProd" parameterType="com.dayou.vo.MajorProductionVO" resultType="com.dayou.vo.MajorProductionVO">
  672. SELECT
  673. m.id as majorId,
  674. m.order_id,
  675. m.financial,
  676. mp.id,
  677. mp.name,
  678. mp.report_no,
  679. mp.standard_amount,
  680. (case mp.production when 'STATEMENT' THEN '意见书' when 'REPORT' THEN '报告' when 'LETTER' THEN '复评函' else '' end) production,
  681. u.NAME AS principal,
  682. u1.NAME AS clientManager,
  683. cc.NAME AS clienteleName,
  684. orf.id AS orderFundId,
  685. orf.should_amount as orderShouldAmount,
  686. off.production_should_amount as shouldAmount,
  687. off.id as productionFundId,
  688. off.real_amount,
  689. fi.invoiceAmount,
  690. ifnull(( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 order by created desc limit 1 ),
  691. ( SELECT declare_result FROM commission_declare WHERE business_id = m.id and production_id is null AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 order by created desc limit 1)) as mDeclareResult,
  692. ifnull(( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 order by created desc limit 1),
  693. ( SELECT declare_result FROM commission_declare WHERE business_id = m.id and production_id is null AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 order by created desc limit 1)) as eDeclareResult
  694. FROM
  695. major_production mp
  696. left join major m on m.id = mp.major_id
  697. INNER JOIN ( SELECT id,business_id,should_amount FROM order_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) orf ON orf.business_id = m.id
  698. LEFT JOIN ( SELECT id,business_id,production_no,real_amount,standard_amount,production_should_amount,production_type FROM production_fund WHERE business_type = 'MAJOR_BUSINESS' AND deleted = 0 ) off ON (off.business_id = m.id and off.production_no = mp.report_no and off.production_type = mp.production)
  699. LEFT JOIN user u ON u.id = m.principal_id
  700. LEFT JOIN user u1 ON u1.id = m.client_manager_id
  701. LEFT JOIN customer_company cc ON cc.id = m.clientele_id
  702. left join (select sum(real_amount) as invoiceAmount,order_fund_id,production_fund_id from finance_invoice where state='已开票' and deleted = 0 GROUP BY production_fund_id) fi on (fi.order_fund_id = orf.id and fi.production_fund_id = off.id)
  703. WHERE
  704. m.deleted = 0
  705. AND mp.deleted = 0
  706. AND m.client_manager_id = #{vo.clientManagerId}
  707. <if test="vo!=null and vo.hasRealAmount!=null and vo.hasRealAmount==true">
  708. and off.real_amount IS NOT NULL
  709. </if>
  710. <if test="vo!=null and vo.hasRealAmount!=null and vo.hasRealAmount==false">
  711. and off.real_amount IS NULL
  712. </if>
  713. <if test="vo!=null and vo.name!=null and vo.name !=''">
  714. and mp.name like concat ('%',#{vo.name},'%')
  715. </if>
  716. <if test="vo!=null and vo.orderId!=null and vo.orderId !=''">
  717. and m.order_id like concat ('%',#{vo.orderId},'%')
  718. </if>
  719. <if test="vo!=null and vo.reportNo!=null and vo.reportNo !=''">
  720. and mp.report_no like concat ('%',#{vo.reportNo},'%')
  721. </if>
  722. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='审核通过'">
  723. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) = '审核通过'
  724. </if>
  725. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='审核拒绝'">
  726. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) = '审核拒绝'
  727. </if>
  728. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='审核中'">
  729. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) = '审核中'
  730. </if>
  731. <if test="vo!=null and vo.mDeclareResult!=null and vo.mDeclareResult =='未申报'">
  732. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_MARKET' AND deleted = 0 ) is null
  733. </if>
  734. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='审核通过'">
  735. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) = '审核通过'
  736. </if>
  737. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='审核拒绝'">
  738. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) = '审核拒绝'
  739. </if>
  740. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='审核中'">
  741. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) = '审核中'
  742. </if>
  743. <if test="vo!=null and vo.eDeclareResult!=null and vo.eDeclareResult =='未申报'">
  744. and ( SELECT declare_result FROM commission_declare WHERE business_id = m.id AND production_id = mp.id AND business_type = 'COMMISSION_DECLARE_MAJOR_EVALUATE' AND deleted = 0 ) is null
  745. </if>
  746. ORDER BY
  747. <if test="vo!=null and vo.invoiceAmount!=null">
  748. fi.invoiceAmount=${vo.invoiceAmount} desc,
  749. </if>
  750. mp.created DESC
  751. </select>
  752. <update id="cancelDelivery">
  753. update major_production set delivery = 0 ,delivery_date = null where major_id = #{businessId} and report_no = #{businessSubId} and production = #{productionType}
  754. </update>
  755. <select id="getMajorProductionById" parameterType="java.lang.Long" resultType="com.dayou.vo.MajorProductionVO">
  756. SELECT
  757. mp.id,
  758. mp.major_id,
  759. m.order_id,
  760. mp.report_no,
  761. mp.production,
  762. m.client_manager_id,
  763. m.department_id,
  764. d.leader_id as departmentLeaderId
  765. FROM
  766. major_production mp
  767. LEFT JOIN major m ON m.id = mp.major_id
  768. left join department d on d.id = m.department_id
  769. WHERE
  770. mp.id = #{productionId} and mp.deleted = 0 and m.deleted = 0
  771. </select>
  772. <select id="getProductionNosByMajorId" parameterType="java.lang.Long" resultType="java.lang.String">
  773. select report_no from major_production where major_id = #{majorId} and deleted = 0
  774. </select>
  775. <select id="getSecondCheckId" resultType="java.lang.Long">
  776. select second_check_id from major_production where major_id =#{businessId} and report_no = #{businessMinId} and deleted = 0
  777. </select>
  778. <select id="getEvaluateAmountByProductionNo" parameterType="java.lang.String" resultType="com.dayou.entity.MajorProduction">
  779. SELECT
  780. mp.id,
  781. mp.work_purpose,
  782. mp.evaluate_amount,
  783. m.business_object_type,
  784. mp.production,
  785. mp.is_record
  786. FROM
  787. major_production mp
  788. LEFT JOIN major m ON m.id = mp.major_id
  789. WHERE
  790. mp.report_no = #{toMergeNumber} and mp.deleted = 0
  791. </select>
  792. <select id="findMaxLetterNoByBusinessId" parameterType="java.lang.Long" resultType="java.lang.String">
  793. SELECT
  794. max( letter_no )
  795. FROM
  796. major_target
  797. WHERE
  798. major_id = #{businessId}
  799. AND deleted = 0
  800. </select>
  801. </mapper>