BizWorkOrderMapper.xml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. </resultMap>
  9. <select id="selectStarMonthList" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  10. SELECT t1.*, t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  11. task_type_detail_name, t5.nick_name as service_name, t7.account_name as from_company_name
  12. FROM biz_work_order t1
  13. left join biz_company t2 on t2.id = t1.company_id
  14. left join biz_task_type t3 on t3.id = t1.task_type_id
  15. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  16. left join biz_tenant t7 on t7.id = t1.tenant_id
  17. left join sys_user t5 on t5.user_id = t1.service_id
  18. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  19. (t1.deleted = 0 or t1.deleted = 1)
  20. <if test="id != null ">AND t1.id = #{id}</if>
  21. <if test="ids != null and ids.size() > 0">
  22. AND t1.id IN
  23. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  24. #{item,jdbcType=BIGINT}
  25. </foreach>
  26. </if>
  27. <if test="companyName != null and companyName!=''">AND t2.name like concat('%', #{companyName}, '%')</if>
  28. <if test="tenantId != null ">
  29. <!-- AND exists (select 1 from biz_entrust t1.tenant_id = tenant_id where )-->
  30. AND t1.tenant_id = #{tenantId}
  31. </if>
  32. <if test="companyId != null ">AND t1.company_id = #{companyId}</if>
  33. <if test="type != null ">AND t1.type = #{type}</if>
  34. <if test="noContract != null ">AND t1.no_contract = #{noContract}</if>
  35. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  36. <if test="taskTypeId != null ">AND t1.task_type_id = #{taskTypeId}</if>
  37. <if test="startMonth != null ">AND t1.start_month &lt;= #{startMonth}</if>
  38. <if test="startMonth != null ">AND t1.end_month &gt;= #{startMonth}</if>
  39. <if test="monthNum != null ">AND t1.month_num = #{monthNum}</if>
  40. <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
  41. <if test="currentMonth != null">AND t1.start_month != 0 AND DATE_FORMAT(#{currentMonth}, '%Y-%m-%d') &gt;=
  42. (case when t1.task_type_id
  43. = 1 then DATE_ADD(t1.start_month,interval 1 month) else t1.start_month end) and
  44. DATE_FORMAT(#{currentMonth}, '%Y-%m-%d') &lt;=
  45. (case when t1.end_month = 0 then DATE_FORMAT(#{currentMonth}, '%Y-%m-%d') when t1.task_type_id = 1 then
  46. DATE_ADD(t1.end_month,interval 1 month) else t1.end_month end)
  47. </if>
  48. <if test="toTenantId != null and currentMonth != null">
  49. AND exists (select 1 from biz_entrust t6 where t6.deleted = 0 and t6.to_tenant_id = #{toTenantId} and
  50. t6.work_month = #{currentMonth} and t1.id = t6.work_order_id )
  51. </if>
  52. <if test="toTenantId != null">
  53. AND exists (select 1 from biz_entrust t6 where t6.deleted = 0 and t6.to_tenant_id = #{toTenantId} and
  54. t1.id = t6.work_order_id )
  55. </if>
  56. </trim>
  57. </select>
  58. <select id="getList" parameterType="BizWorkOrder" resultMap="BizWorkOrderResult">
  59. SELECT t1.*, t2.name as company_name, t2.social_credit_code, t3.name as task_type_name, t4.name as
  60. task_type_detail_name, t5.nick_name as service_name, t7.account_name as
  61. from_company_name,t6.alter_type,t6.address_style,
  62. t6.fiction_address_id,t6.province as inputProvince,t6.city as inputCity,t6.district as inputDistrict,
  63. COALESCE(t8.account_name, t5.nick_name) as toAccountName
  64. FROM biz_work_order t1
  65. left join biz_company t2 on t2.id = t1.company_id
  66. left join biz_task_type t3 on t3.id = t1.task_type_id
  67. left join biz_task_type_detail t4 on t4.id = t1.task_type_detail_id
  68. left join biz_tenant t7 on t7.id = t1.tenant_id
  69. left join sys_user t5 on t5.user_id = t1.service_id
  70. left join biz_archive_input_detail t6 ON t6.id = t1.contract_detail_id
  71. left join (select tt1.*,tt2.account_name from biz_entrust tt1 LEFT JOIN biz_tenant tt2
  72. on tt1.to_tenant_id =tt2.id and tt1.deleted = 0) t8 on t8.work_order_id = t1.id and t8.deleted = 0 and
  73. t8.task_type_id = t1.task_type_id and t8.work_month = #{workDate}
  74. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  75. t1.deleted = 0 and t2.deleted = 0
  76. <if test="id != null ">AND t1.id = #{id}</if>
  77. <if test="ids != null and ids.size() > 0">
  78. AND t1.id IN
  79. <foreach collection="ids" index="index" item="item" separator="," open="(" close=")">
  80. #{item,jdbcType=BIGINT}
  81. </foreach>
  82. </if>
  83. <if test="toAccountName != null and toAccountName!=''">AND (COALESCE ( t8.account_name, t5.nick_name ) LIKE
  84. concat( '%', #{toAccountName}, '%' ))
  85. </if>
  86. <if test="fromCompanyName != null and fromCompanyName!=''">AND t7.account_name LIKE
  87. concat( '%', #{fromCompanyName}, '%' )
  88. </if>
  89. <if test="companyName != null and companyName!=''">AND t2.name like concat('%', #{companyName}, '%')</if>
  90. <if test="tenantId != null ">
  91. <!-- AND exists (select 1 from biz_entrust t1.tenant_id = tenant_id where )-->
  92. AND t1.tenant_id = #{tenantId}
  93. </if>
  94. <if test="companyId != null ">AND t1.company_id = #{companyId}</if>
  95. <if test="type != null ">AND t1.type = #{type}</if>
  96. <if test="noContract != null ">AND t1.no_contract = #{noContract}</if>
  97. <if test="workOrderNo != null and workOrderNo != ''">AND t1.work_order_no = #{workOrderNo}</if>
  98. <if test="taskTypeId != null ">AND t1.task_type_id = #{taskTypeId}</if>
  99. <if test="startMonth != null ">AND t1.start_month = #{startMonth}</if>
  100. <if test="endMonth != null ">AND t1.end_month = #{endMonth}</if>
  101. <if test="monthNum != null ">AND t1.month_num = #{monthNum}</if>
  102. <if test="isStop != null ">AND t1.is_stop = #{isStop}</if>
  103. <if test="currentMonth != null">AND t1.start_month != 0 AND DATE_FORMAT(#{currentMonth}, '%Y-%m-%d') &gt;=
  104. (case when t1.task_type_id
  105. = 1 then DATE_ADD(t1.start_month,interval 1 month) else t1.start_month end) and
  106. DATE_FORMAT(#{currentMonth}, '%Y-%m-%d') &lt;=
  107. (case when t1.is_continue=1 then #{currentMonth} when t1.end_month = 0 then DATE_FORMAT(#{currentMonth},
  108. '%Y-%m-%d') when t1.task_type_id = 1 then
  109. DATE_ADD(t1.end_month,interval 1 month) else t1.end_month end)
  110. </if>
  111. <if test="toTenantId != null and currentMonth != null">
  112. AND exists (select 1 from biz_entrust t6 where t6.deleted = 0 and t6.to_tenant_id = #{toTenantId} and
  113. t6.work_month = #{currentMonth} and t1.id = t6.work_order_id )
  114. </if>
  115. <if test="toTenantId != null">
  116. AND exists (select 1 from biz_entrust t6 where t6.deleted = 0 and t6.to_tenant_id = #{toTenantId} and
  117. t1.id = t6.work_order_id )
  118. </if>
  119. </trim>
  120. ORDER BY t1.create_time DESC
  121. </select>
  122. <select id="getHistoryList" resultType="cn.ezhizao.project.business.workOrder.domain.vo.EntrustRes">
  123. SELECT
  124. t1.id,t1.work_order_id,t2.account_name as toAccountName,
  125. t3.name as companyName,t3.social_credit_code,
  126. t4.name as task_type_name,t5.type,t5.start_month,
  127. t5.end_month,t5.month_num,t7.account_name as
  128. fromCompanyName
  129. FROM
  130. biz_entrust t1
  131. LEFT JOIN biz_tenant t2 on t1.to_tenant_id =t2.id
  132. LEFT Join biz_company t3 on t3.id = t1.company_id
  133. left join biz_task_type t4 on t4.id = t1.task_type_id
  134. LEFT JOIN biz_work_order t5 on t5.id = t1.work_order_id
  135. LEFT JOIN biz_tenant t7 on t1.from_tenant_id =t7.id
  136. <where>
  137. t1.deleted = 0 and t5.id is not null
  138. AND t5.type = 1
  139. AND t5.start_month != 0
  140. and t5.deleted = 0
  141. <if test="fromTenantId != null and fromTenantId != ''">
  142. AND t1.from_tenant_id = #{fromTenantId}
  143. </if>
  144. <if test="toTenantId != null and toTenantId != ''">
  145. AND t1.to_tenant_id = #{toTenantId}
  146. </if>
  147. <if test="fromCompanyName != null and fromCompanyName != ''">
  148. AND t7.account_name like concat('%', #{fromCompanyName}, '%')
  149. </if>
  150. <if test="date == null">
  151. and t5.start_month &lt; DATE_FORMAT(CURRENT_DATE (), '%Y-%m-01')
  152. AND MONTH ( t1.work_month ) &lt;MONTH(CURRENT_DATE ())
  153. </if>
  154. <if test="date != null">
  155. AND t1.work_month = #{date}
  156. </if>
  157. <if test="companyName != null and companyName != ''">
  158. AND t3.name like concat('%', #{companyName}, '%')
  159. </if>
  160. <if test="toAccountName != null and toAccountName!=''">
  161. AND t2.account_name like concat( '%', #{toAccountName}, '%' )
  162. </if>
  163. </where>
  164. ORDER BY
  165. t5.start_month DESC
  166. </select>
  167. <delete id="physicalDelete">
  168. DELETE FROM biz_work_order
  169. <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
  170. <if test="id != null">
  171. id = #{id} AND
  172. </if>
  173. <!-- 删除条件为其他外键可以在这里加 -->
  174. </trim>
  175. </delete>
  176. <insert id="insertTasks">
  177. <foreach collection="tableValues" item="item" index="index" separator=";">
  178. insert into ${item.tableName} (
  179. id,
  180. company_id,
  181. work_order_id,
  182. tenant_id,
  183. create_time,
  184. creator_id
  185. )values (
  186. #{item.id,jdbcType=BIGINT},
  187. #{item.companyId,jdbcType=BIGINT},
  188. #{item.workOrderId,jdbcType=BIGINT},
  189. #{item.tenantId,jdbcType=BIGINT},
  190. sysdate(),
  191. #{item.creatorId,jdbcType=BIGINT}
  192. )
  193. </foreach>
  194. </insert>
  195. <update id="stopTasks">
  196. <foreach collection="tableValues" item="item" index="index" separator=";">
  197. update ${item.tableName} set is_stop = 1,deleted = 1 where work_order_id = #{item.workOrderId}
  198. </foreach>
  199. </update>
  200. <update id="updateTasks">
  201. <foreach collection="tableValues" item="item" index="index" separator=";">
  202. update ${item.tableName} set is_stop = 0,deleted = 0 where work_order_id = #{item.workOrderId}
  203. </foreach>
  204. </update>
  205. <update id="updateByIdAndDeleted">
  206. update biz_work_order set deleted = #{deleted},is_continue = #{isContinue},is_stop=#{isStop}
  207. where id = #{id}
  208. </update>
  209. </mapper>