BizWorkOrderMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE mapper
  3. PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5. <mapper namespace="cn.ezhizao.project.business.workOrder.mapper.BizWorkOrderMapper">
  6. <resultMap type="cn.ezhizao.project.business.workOrder.domain.BizWorkOrder" id="BizWorkOrderResult">
  7. <id column="id" property="id"/>
  8. <result column="company_id" jdbcType="BIGINT" property="companyId"/>
  9. <collection property="records" select="getRecords" column="id"/>
  10. </resultMap>
  11. <resultMap type="cn.ezhizao.project.business.workOrder.domain.BizWorkOrderRecord"
  12. id="BizWorkOrderRecordResult">
  13. <id column="id" property="id"/>
  14. </resultMap>
  15. <select id="getList" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  16. SELECT t1.*, t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  17. task_type_detail_name, t5.nick_name as service_name, t2.is_zero,t2.tax_type,t6.alter_type,t6.address_style,t6.fiction_address_id,t6.province as inputProvince,t6.city as inputCity,t6.district as inputDistrict
  18. FROM biz_work_order t1
  19. left join biz_company t2 on t2.id = t1.company_id
  20. left join biz_task_type t3 on t3.id = t1.task_type_id
  21. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  22. left join sys_user t5 on t5.user_id = t1.service_id
  23. LEFT JOIN biz_archive_input_detail t6 ON t6.id = t1.contract_detail_id
  24. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  25. t1.deleted = 0 and t6.from_id = 0
  26. <if test="id != null "> AND t1.id = #{id}</if>
  27. <if test="contractDetailId != null "> AND t1.contract_detail_id = #{contractDetailId}</if>
  28. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  29. <if test="companyId != null "> AND t1.company_id = #{companyId}</if>
  30. <if test="type != null ">AND t1.type = #{type}</if>
  31. <if test=" serviceId != null">AND t1.service_id = #{serviceId}</if>
  32. <if test="noContract != null ">AND t1.no_contract = #{noContract}</if>
  33. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  34. <if test="startMonth != null ">AND t1.start_month = #{startMonth}</if>
  35. <if test="endMonth != null ">AND t1.end_month = #{endMonth}</if>
  36. <if test="monthNum != null ">AND t1.month_num = #{monthNum}</if>
  37. <if test="companyName != null and companyName != '' "> AND t2.name like concat('%', #{companyName}, '%')</if>
  38. <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
  39. <if test="year != null ">
  40. AND t1.start_month > 0
  41. <if test="month != null and month != ''">
  42. AND concat(#{year}, '-', #{month}, '-01') &gt;= (case when t1.task_type_id = 1 then DATE_ADD(t1.start_month, interval 1 month) else t1.start_month end) and concat(#{year}, '-', #{month}, '-01') &lt;= (case when t1.task_type_id = 1 then DATE_ADD(t1.end_month,interval 1 month) else t1.end_month end)
  43. </if>
  44. <if test="month == null or month == ''">
  45. AND #{year} >= (case when t1.task_type_id = 1 then DATE_FORMAT(DATE_ADD(t1.start_month,interval 1 month), '%Y') else DATE_FORMAT(t1.start_month, '%Y') end) AND #{year} &lt;= (case when t1.end_month = 0 then #{year} when t1.task_type_id = 1 then DATE_FORMAT(DATE_ADD(t1.end_month,interval 1 month), '%Y') else DATE_FORMAT(t1.end_month, '%Y') end)
  46. </if>
  47. </if>
  48. <if test="status != null and status > 0">
  49. and exists (select 1 from biz_work_order_record t6 where t6.deleted = 0 and t6.work_order_id = t1.id
  50. <if test="year != null">
  51. and t6.year = #{year}
  52. </if>
  53. <if test="month != null">
  54. and t6.month = #{month}
  55. </if>
  56. and t6.status = #{status} and t6.from_id = 0)
  57. </if>
  58. <if test="status != null and status == 0">
  59. and not exists (select 1 from biz_work_order_record t6 where t6.deleted = 0 and t6.work_order_id = t1.id
  60. <if test="year != null">
  61. and t6.year = #{year}
  62. </if>
  63. <if test="month != null">
  64. and t6.month = #{month}
  65. </if>
  66. and t6.status > 0 and t6.from_id = 0)
  67. </if>
  68. </trim>
  69. </select>
  70. <select id="getRecords" resultMap="BizWorkOrderRecordResult">
  71. SELECT * FROM biz_work_order_record WHERE deleted = 0 AND work_order_id = #{id}
  72. </select>
  73. <update id="setContinue" >
  74. UPDATE biz_work_order SET is_continue =#{state}
  75. where id in
  76. <foreach collection="ids" item="id" separator="," open="(" close=")">
  77. #{id}
  78. </foreach>
  79. </update>
  80. <select id="getIndexList" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  81. SELECT t1.*,t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  82. task_type_detail_name, t5.nick_name as service_name, t2.is_zero
  83. FROM biz_work_order t1
  84. left join biz_company t2 on t2.id = t1.company_id
  85. left join biz_task_type t3 on t3.id = t1.task_type_id
  86. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  87. left join sys_user t5 on t5.user_id = t1.service_id
  88. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  89. t1.deleted = 0
  90. <if test="id != null "> AND t1.id = #{id}</if>
  91. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  92. <if test="companyId != null "> AND t1.company_id = #{companyId}</if>
  93. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  94. <if test=" serviceId != null">AND t1.service_id = #{serviceId}</if>
  95. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  96. <if test="companyName != null and companyName != '' "> AND t2.name like concat('%', #{companyName}, '%')</if>
  97. AND NOT EXISTS (
  98. SELECT 1 FROM biz_entrust t7 WHERE t7.work_order_id =t1.id
  99. )
  100. </trim>
  101. </select>
  102. <select id="getList2" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  103. SELECT t1.*, t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  104. task_type_detail_name, t5.nick_name as service_name, t2.is_zero,t2.tax_type FROM biz_work_order t1
  105. left join biz_company t2 on t2.id = t1.company_id
  106. left join biz_task_type t3 on t3.id = t1.task_type_id
  107. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  108. left join sys_user t5 on t5.user_id = t1.service_id
  109. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  110. t1.deleted = 0 and t1.is_stop = 0
  111. <if test="id != null "> AND t1.id = #{id}</if>
  112. <if test="contractDetailId != null "> AND t1.contract_detail_id = #{contractDetailId}</if>
  113. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  114. <if test="companyId != null "> AND t1.company_id = #{companyId}</if>
  115. <if test="type != null ">AND t1.type = #{type}</if>
  116. <if test=" serviceId != null">AND t1.service_id = #{serviceId}</if>
  117. <if test="noContract != null ">AND t1.no_contract = #{noContract}</if>
  118. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  119. <if test="startMonth != null ">AND t1.start_month = #{startMonth}</if>
  120. <if test="endMonth != null ">AND t1.end_month = #{endMonth}</if>
  121. <if test="monthNum != null ">AND t1.month_num = #{monthNum}</if>
  122. <if test="companyName != null and companyName != '' "> AND t2.name like concat('%', #{companyName}, '%')</if>
  123. <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
  124. <if test="year != null ">
  125. AND t1.start_month > 0
  126. <if test="month != null and month != ''">
  127. AND concat(#{year}, '-', #{month}, '-01') &gt;= (case when t1.task_type_id = 1 then DATE_ADD(t1.start_month, interval 1 month) else t1.start_month end) and concat(#{year}, '-', #{month}, '-01') &lt;= (case when t1.task_type_id = 1 then DATE_ADD(t1.end_month,interval 1 month) else t1.end_month end)
  128. </if>
  129. <if test="month == null or month == ''">
  130. AND #{year} >= (case when t1.task_type_id = 1 then DATE_FORMAT(DATE_ADD(t1.start_month,interval 1 month), '%Y') else DATE_FORMAT(t1.start_month, '%Y') end) AND #{year} &lt;= (case when t1.end_month = 0 then #{year} when t1.task_type_id = 1 then DATE_FORMAT(DATE_ADD(t1.end_month,interval 1 month), '%Y') else DATE_FORMAT(t1.end_month, '%Y') end)
  131. </if>
  132. </if>
  133. </trim>
  134. </select>
  135. <delete id="physicalDelete">
  136. DELETE FROM biz_work_order
  137. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  138. <if test="id != null">
  139. id = #{id} AND
  140. </if>
  141. <!-- 删除条件为其他外键可以在这里加 -->
  142. </trim>
  143. </delete>
  144. <insert id="insertTasks">
  145. <foreach collection="tableValues" item="item" index="index" separator=";">
  146. insert into ${item.tableName} (
  147. id,
  148. company_id,
  149. work_order_id,
  150. tenant_id,
  151. create_time,
  152. creator_id
  153. ) values (
  154. #{item.id},
  155. #{item.companyId},
  156. #{item.workOrderId},
  157. #{item.tenantId},
  158. sysdate(),
  159. #{item.creatorId}
  160. )
  161. <!-- select-->
  162. <!-- #{item.id},-->
  163. <!-- #{item.workOrderId},-->
  164. <!-- company_id,-->
  165. <!-- tenant_id,-->
  166. <!-- sysdate(),-->
  167. <!-- #{item.creatorId}-->
  168. <!-- from biz_work_order where id = #{item.workOrderId}-->
  169. <!-- and not exists (select 1 from ${item.tableName} where ${item.tableName}.company_id = biz_work_order.company_id and is_stop = 0
  170. )-->
  171. </foreach>
  172. </insert>
  173. <update id="stopTasks">
  174. <foreach collection="tableValues" item="item" index="index" separator=";">
  175. update ${item.tableName} set is_stop = 1 where work_order_id = #{item.workOrderId}
  176. </foreach>
  177. </update>
  178. <update id="updateByTenantId">
  179. update biz_work_order set contract_id = 0,contract_detail_id = 0 where tenant_id = #{tenantId}
  180. </update>
  181. </mapper>