BizWorkOrderMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. </resultMap>
  10. <resultMap type="cn.ezhizao.project.business.workOrder.domain.BizWorkOrderRecord"
  11. id="BizWorkOrderRecordResult">
  12. <id column="id" property="id"/>
  13. </resultMap>
  14. <select id="getList" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  15. SELECT t1.*, t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  16. 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
  17. FROM biz_work_order t1
  18. left join biz_company t2 on t2.id = t1.company_id
  19. left join biz_task_type t3 on t3.id = t1.task_type_id
  20. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  21. left join sys_user t5 on t5.user_id = t1.service_id
  22. LEFT JOIN biz_archive_input_detail t6 ON t6.id = t1.contract_detail_id
  23. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  24. t1.deleted = 0 and t6.from_id = 0
  25. <if test="id != null "> AND t1.id = #{id}</if>
  26. <if test="contractDetailId != null "> AND t1.contract_detail_id = #{contractDetailId}</if>
  27. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  28. <if test="companyId != null "> AND t1.company_id = #{companyId}</if>
  29. <if test="type != null ">AND t1.type = #{type}</if>
  30. <if test=" serviceId != null">AND t1.service_id = #{serviceId}</if>
  31. <if test="noContract != null ">AND t1.no_contract = #{noContract}</if>
  32. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  33. <if test="startMonth != null ">AND t1.start_month = #{startMonth}</if>
  34. <if test="endMonth != null ">AND t1.end_month = #{endMonth}</if>
  35. <if test="monthNum != null ">AND t1.month_num = #{monthNum}</if>
  36. <if test="companyName != null and companyName != '' "> AND t2.name like concat('%', #{companyName}, '%')</if>
  37. <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
  38. <if test="year != null ">
  39. AND t1.start_month > 0
  40. <if test="month != null and month != ''">
  41. 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)
  42. </if>
  43. <if test="month == null or month == ''">
  44. 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)
  45. </if>
  46. </if>
  47. <if test="status != null and status > 0">
  48. and exists (select 1 from biz_work_order_record t6 where t6.deleted = 0 and t6.work_order_id = t1.id
  49. <if test="year != null">
  50. and t6.year = #{year}
  51. </if>
  52. <if test="month != null">
  53. and t6.month = #{month}
  54. </if>
  55. and t6.status = #{status} and t6.from_id = 0)
  56. </if>
  57. <if test="status != null and status == 0">
  58. and not exists (select 1 from biz_work_order_record t6 where t6.deleted = 0 and t6.work_order_id = t1.id
  59. <if test="year != null">
  60. and t6.year = #{year}
  61. </if>
  62. <if test="month != null">
  63. and t6.month = #{month}
  64. </if>
  65. and t6.status > 0 and t6.from_id = 0)
  66. </if>
  67. </trim>
  68. </select>
  69. <select id="getRecords" resultMap="BizWorkOrderRecordResult">
  70. SELECT * FROM biz_work_order_record WHERE deleted = 0 AND work_order_id = #{id}
  71. </select>
  72. <update id="setContinue" >
  73. UPDATE biz_work_order SET is_continue =#{state}
  74. where id in
  75. <foreach collection="ids" item="id" separator="," open="(" close=")">
  76. #{id}
  77. </foreach>
  78. </update>
  79. <select id="getIndexList" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  80. SELECT t1.*,t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  81. task_type_detail_name, t5.nick_name as service_name, t2.is_zero
  82. FROM biz_work_order t1
  83. left join biz_company t2 on t2.id = t1.company_id
  84. left join biz_task_type t3 on t3.id = t1.task_type_id
  85. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  86. left join sys_user t5 on t5.user_id = t1.service_id
  87. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  88. t1.deleted = 0
  89. <if test="id != null "> AND t1.id = #{id}</if>
  90. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  91. <if test="companyId != null "> AND t1.company_id = #{companyId}</if>
  92. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  93. <if test=" serviceId != null">AND t1.service_id = #{serviceId}</if>
  94. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  95. <if test="companyName != null and companyName != '' "> AND t2.name like concat('%', #{companyName}, '%')</if>
  96. AND NOT EXISTS (
  97. SELECT 1 FROM biz_entrust t7 WHERE t7.work_order_id =t1.id
  98. )
  99. </trim>
  100. </select>
  101. <select id="getList2" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  102. SELECT t1.*, t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  103. task_type_detail_name, t5.nick_name as service_name, t2.is_zero,t2.tax_type FROM biz_work_order t1
  104. left join biz_company t2 on t2.id = t1.company_id
  105. left join biz_task_type t3 on t3.id = t1.task_type_id
  106. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  107. left join sys_user t5 on t5.user_id = t1.service_id
  108. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  109. t1.deleted = 0
  110. <if test="id != null "> AND t1.id = #{id}</if>
  111. <if test="contractDetailId != null "> AND t1.contract_detail_id = #{contractDetailId}</if>
  112. <if test="tenantId != null "> AND t1.tenant_id = #{tenantId}</if>
  113. <if test="companyId != null "> AND t1.company_id = #{companyId}</if>
  114. <if test="type != null ">AND t1.type = #{type}</if>
  115. <if test=" serviceId != null">AND t1.service_id = #{serviceId}</if>
  116. <if test="noContract != null ">AND t1.no_contract = #{noContract}</if>
  117. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  118. <if test="startMonth != null ">AND t1.start_month = #{startMonth}</if>
  119. <if test="endMonth != null ">AND t1.end_month = #{endMonth}</if>
  120. <if test="monthNum != null ">AND t1.month_num = #{monthNum}</if>
  121. <if test="companyName != null and companyName != '' "> AND t2.name like concat('%', #{companyName}, '%')</if>
  122. <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
  123. <if test="year != null ">
  124. AND t1.start_month > 0
  125. <if test="month != null and month != ''">
  126. 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)
  127. </if>
  128. <if test="month == null or month == ''">
  129. 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)
  130. </if>
  131. </if>
  132. </trim>
  133. </select>
  134. <delete id="physicalDelete">
  135. DELETE FROM biz_work_order
  136. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  137. <if test="id != null">
  138. id = #{id} AND
  139. </if>
  140. <!-- 删除条件为其他外键可以在这里加 -->
  141. </trim>
  142. </delete>
  143. <insert id="insertTasks">
  144. <foreach collection="tableValues" item="item" index="index" separator=";">
  145. insert into ${item.tableName} (
  146. id,
  147. company_id,
  148. work_order_id,
  149. tenant_id,
  150. create_time,
  151. creator_id
  152. ) values (
  153. #{item.id},
  154. #{item.companyId},
  155. #{item.workOrderId},
  156. #{item.tenantId},
  157. sysdate(),
  158. #{item.creatorId}
  159. )
  160. <!-- select-->
  161. <!-- #{item.id},-->
  162. <!-- #{item.workOrderId},-->
  163. <!-- company_id,-->
  164. <!-- tenant_id,-->
  165. <!-- sysdate(),-->
  166. <!-- #{item.creatorId}-->
  167. <!-- from biz_work_order where id = #{item.workOrderId}-->
  168. <!-- and not exists (select 1 from ${item.tableName} where ${item.tableName}.company_id = biz_work_order.company_id and is_stop = 0
  169. )-->
  170. </foreach>
  171. </insert>
  172. <update id="stopTasks">
  173. <foreach collection="tableValues" item="item" index="index" separator=";">
  174. update ${item.tableName} set is_stop = 1 where work_order_id = #{item.workOrderId}
  175. </foreach>
  176. </update>
  177. <!-- 20241114 设置是否延续的时候用的-->
  178. <update id="stopLoopTasks">
  179. <foreach collection="tableValues" item="item" index="index" separator=";">
  180. update ${item.tableName} set is_stop = 1,deleted = 1 where work_order_id = #{item.workOrderId}
  181. </foreach>
  182. </update>
  183. <update id="updateByTenantId">
  184. update biz_work_order set contract_id = 0,contract_detail_id = 0 where tenant_id = #{tenantId}
  185. </update>
  186. <update id="updateByWorkOrderId"
  187. parameterType="java.util.List">
  188. update biz_work_order set is_stop = 1,no_contract = 1,is_continue=0
  189. WHERE id in
  190. <foreach collection="ids" item="id" index="index" open="(" separator="," close=")">
  191. #{id}
  192. </foreach>
  193. </update>
  194. </mapper>