Sin descripción

TLhzxEmployeeMapper.xml 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  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.yt.zhylplat.moduleLhzx.employee.mapper.TLhzxEmployeeMapper">
  4. <!-- 通用查询映射结果 -->
  5. <resultMap id="BaseResultMap" type="com.yt.zhylplat.moduleLhzx.employee.entity.TLhzxEmployee">
  6. <id column="id" property="id"/>
  7. <result column="maintenance_company_id" property="maintenanceCompanyId"/>
  8. <result column="maintenance_company_name" property="maintenanceCompanyName"/>
  9. <result column="real_name" property="realName"/>
  10. <result column="job_name" property="jobName"/>
  11. <result column="job_title" property="jobTitle"/>
  12. <result column="job_level" property="jobLevel"/>
  13. <result column="sex" property="sex"/>
  14. <result column="id_card_num" property="idCardNum"/>
  15. <result column="tel_phone" property="telPhone"/>
  16. <result column="before_address" property="beforeAddress"/>
  17. <result column="now_address" property="nowAddress"/>
  18. <result column="address_type" property="addressType"/>
  19. <result column="age" property="age"/>
  20. <result column="post_card_num" property="postCardNum"/>
  21. <result column="emp_type" property="empType"/>
  22. <result column="remark" property="remark"/>
  23. <result column="create_user_id" property="createUserId"/>
  24. <result column="create_date" property="createDate"/>
  25. <result column="update_user_id" property="updateUserId"/>
  26. <result column="update_date" property="updateDate"/>
  27. <result column="del_flg" property="delFlg"/>
  28. </resultMap>
  29. <!-- 通用查询结果列 -->
  30. <sql id="Base_Column_List">
  31. id, yh_company_id, yh_company_name, section_id, section_name, real_name, job_name, job_title, job_level, sex, id_card_num, tel_phone, before_address, now_address, address_type, age, post_card_num, emp_type, remark, create_user_id, create_date, update_user_id, update_date, del_flg
  32. </sql>
  33. <select id="findEmpByCompany"
  34. resultType="com.yt.zhylplat.moduleLhzx.road.entity.TLhzxRoadSectionMaintenanceCompany">
  35. </select>
  36. <select id="findEmpBySection"
  37. resultType="com.yt.zhylplat.moduleLhzx.road.entity.TLhzxRoadSectionMaintenanceCompany">
  38. </select>
  39. <select id="findEmpByCompanyId" resultType="com.yt.zhylplat.moduleLhzx.employee.entity.TLhzxEmployee">
  40. select
  41. e.*
  42. from
  43. T_Lhzx_Employee e left join T_Lhzx_Employee_Section TLES on e.id = TLES.employee_id
  44. <where>
  45. and e.del_flg=0
  46. and TLES.del_flg = 0
  47. <if test="allEmp.maintenanceCompanyId!=null">
  48. and e.maintenance_company_id=#{allEmp.maintenanceCompanyId}
  49. </if>
  50. <if test="allEmp.idCardNum!=null and allEmp.idCardNum!=''">
  51. and e.id_card_num =#{allEmp.idCardNum}
  52. </if>
  53. <if test="allEmp.telPhone!=null and allEmp.telPhone!=''">
  54. and e.tel_phone=#{allEmp.telPhone}
  55. </if>
  56. <if test="allEmp.realName!=null and allEmp.realName!=''">
  57. and e.real_name like concat('%',#{allEmp.realName},'%')
  58. </if>
  59. <if test="allEmp.sectionId!=null">
  60. and section_id=#{allEmp.sectionId}
  61. </if>
  62. </where>
  63. </select>
  64. <select id="findEmpAll" resultType="com.yt.zhylplat.moduleLhzx.employee.entity.TLhzxEmployee">
  65. select
  66. *
  67. from
  68. T_Lhzx_Employee e
  69. where
  70. e.del_flg=0
  71. <if test="allEmptwo.idCardNum!=null and allEmptwo.idCardNum!=''">
  72. and e.id_card_num=#{allEmptwo.idCardNum}
  73. </if>
  74. <if test="allEmptwo.telPhone!=null and allEmptwo.telPhone!=''">
  75. and e.tel_phone=#{allEmptwo.telPhone}
  76. </if>
  77. <if test="allEmptwo.realName!=null and allEmptwo.realName!=''">
  78. and e.real_name like concat('%',#{allEmptwo.realName},'%')
  79. </if>
  80. </select>
  81. <select id="sectionPage" resultType="com.yt.zhylplat.moduleLhzx.road.entity.TLhzxRoadSectionMaintenanceCompany">
  82. SELECT DISTINCT
  83. emp.section_id as sectionId,
  84. emp.section_name,
  85. emp.maintenance_company_id,
  86. emp.maintenance_company_name,
  87. emp.section_type as sectionType,
  88. project_manager AS projectManager,
  89. project_manager_tel,
  90. charge_leader AS chargeLeader,
  91. charge_leader_tel AS chargeLeaderTel,
  92. maneger AS managerCount,
  93. worker AS workerCount,
  94. emp.OnSh as sumOnSh,
  95. emp.LeaveSh as sumLeaveSh,
  96. emp.BackSh as sumBackSh,
  97. emp.Isolation as sumIsolation,
  98. (select operation_num FROM T_Lhzx_Maintenance_Completion_Record where del_flg=0 and section_id = emp.section_id and maintenance_company_id = emp.maintenance_company_id order by create_date desc limit 1) as operation_num
  99. FROM (
  100. SELECT
  101. es.section_id,
  102. s.section_name,
  103. maintenance_company_id,
  104. maintenance_company_name,
  105. s.section_type,
  106. sum(IF(emp_type=0, 1, 0)) AS maneger,
  107. sum(IF(emp_type!=0, 1, 0)) AS worker,
  108. sum(IF(leaving_shanghai_sta=0,1,0)) as OnSh,
  109. sum(IF(leaving_shanghai_sta=1, 1, 0)) as LeaveSh,
  110. sum(IF(leaving_shanghai_sta=2, 1, 0)) as BackSh,
  111. sum(IF(leaving_shanghai_sta=3, 1, 0)) as Isolation
  112. FROM T_Lhzx_Employee e
  113. left join T_Lhzx_Employee_Section es on e.id = es.employee_id
  114. left join T_Lhzx_Section s on es.section_id = s.id
  115. WHERE e.del_flg = 0
  116. and e.emp_sta=0
  117. and es.section_id is not null
  118. GROUP BY
  119. es.section_id,
  120. s.section_name,
  121. maintenance_company_id,
  122. maintenance_company_name
  123. ) AS emp
  124. LEFT JOIN (
  125. SELECT DISTINCT section_id,
  126. maintenance_company_id,
  127. project_manager,
  128. project_manager_tel,
  129. charge_leader,
  130. charge_leader_tel
  131. FROM T_Lhzx_Road_Section_Maintenance_Company
  132. WHERE del_flg = 0
  133. ) AS rsmc ON emp.maintenance_company_id = rsmc.maintenance_company_id and rsmc.section_id = emp.section_id
  134. <where>
  135. <if test="spage.maintenanceCompanyId!=null and spage.maintenanceCompanyId!=''">
  136. and rsmc.maintenance_company_id=#{spage.maintenanceCompanyId}
  137. </if>
  138. <if test="spage.maintenanceCompanyName!=null and spage.maintenanceCompanyName!=''">
  139. and emp.maintenance_company_name like concat('%',#{spage.maintenanceCompanyName},'%')
  140. </if>
  141. <if test="spage.sectionName!=null and spage.sectionName!=''">
  142. and emp.section_name like concat('%',#{spage.sectionName},'%')
  143. </if>
  144. <if test="spage.sectionType!=null">
  145. and emp.section_type =#{spage.sectionType}
  146. </if>
  147. </where>
  148. ORDER BY
  149. emp.section_type, emp.section_id asc,emp.maintenance_company_id asc
  150. </select>
  151. <select id="comPanyPage" resultType="com.yt.zhylplat.moduleLhzx.road.entity.TLhzxRoadSectionMaintenanceCompany">
  152. SELECT DISTINCT
  153. emp.section_id as sectionId,
  154. emp.section_name,
  155. emp.maintenance_company_id,
  156. emp.maintenance_company_name,
  157. emp.section_type as sectionType,
  158. project_manager AS projectManager,
  159. project_manager_tel,
  160. charge_leader AS chargeLeader,
  161. charge_leader_tel AS chargeLeaderTel,
  162. maneger AS managerCount,
  163. worker AS workerCount,
  164. emp.OnSh as sumOnSh,
  165. emp.LeaveSh as sumLeaveSh,
  166. emp.BackSh as sumBackSh,
  167. emp.Isolation as sumIsolation,
  168. emp.leavecount as leaveCount,
  169. emp.entrycount as entryCount
  170. FROM (
  171. SELECT
  172. es.section_id,
  173. s.section_name,
  174. maintenance_company_id,
  175. maintenance_company_name,
  176. s.section_type,
  177. sum(IF(emp_type=0, 1, 0)) AS maneger,
  178. sum(IF(emp_type!=0, 1, 0)) AS worker,
  179. sum(IF(leaving_shanghai_sta=0,1,0)) as OnSh,
  180. sum(IF(leaving_shanghai_sta=1, 1, 0)) as LeaveSh,
  181. sum(IF(leaving_shanghai_sta=2, 1, 0)) as BackSh,
  182. sum(IF(leaving_shanghai_sta=3, 1, 0)) as Isolation,
  183. sum(if(emp_change_date = CURDATE() and emp_sta=1,1,0)) as leavecount,
  184. sum(if(emp_change_date = CURDATE() and emp_sta=0,1,0)) as entrycount
  185. FROM T_Lhzx_Employee e
  186. left join T_Lhzx_Employee_Section es on e.id = es.employee_id
  187. left join T_Lhzx_Section s on es.section_id = s.id
  188. WHERE e.del_flg = 0
  189. and es.section_id is not null
  190. GROUP BY
  191. es.section_id,
  192. s.section_name,
  193. maintenance_company_id,
  194. maintenance_company_name
  195. ) AS emp
  196. LEFT JOIN (
  197. SELECT DISTINCT section_id,
  198. maintenance_company_id,
  199. project_manager,
  200. project_manager_tel,
  201. charge_leader,
  202. charge_leader_tel
  203. FROM T_Lhzx_Road_Section_Maintenance_Company
  204. WHERE del_flg = 0
  205. ) AS rsmc ON emp.maintenance_company_id = rsmc.maintenance_company_id and rsmc.section_id = emp.section_id
  206. <where>
  207. <if test="cpage.maintenanceCompanyId!=null and cpage.maintenanceCompanyId!=''">
  208. and rsmc.maintenance_company_id=#{cpage.maintenanceCompanyId}
  209. </if>
  210. <if test="cpage.maintenanceCompanyName!=null and cpage.maintenanceCompanyName!=''">
  211. and emp.maintenance_company_name like concat('%',#{cpage.maintenanceCompanyName},'%')
  212. </if>
  213. <if test="cpage.sectionName!=null and cpage.sectionName!=''">
  214. and emp.section_name like concat('%',#{cpage.sectionName},'%')
  215. </if>
  216. <if test="cpage.sectionType!=null">
  217. and emp.section_type =#{cpage.sectionType}
  218. </if>
  219. </where>
  220. ORDER BY
  221. emp.maintenance_company_id,emp.section_id
  222. </select>
  223. <select id="sumOfManagerAndWorker"
  224. resultType="com.yt.zhylplat.moduleLhzx.road.entity.TLhzxRoadSectionMaintenanceCompany">
  225. select
  226. sum(IF(emp_type=0, 1, 0)) as sumManager,
  227. sum(IF(emp_type!=0, 1, 0)) as sumWorker,
  228. sum(IF(leaving_shanghai_sta=0,1,0)) as sumOnSh,
  229. sum(IF(leaving_shanghai_sta=1, 1, 0)) as sumLeaveSh,
  230. sum(IF(leaving_shanghai_sta=2, 1, 0)) as sumBackSh,
  231. sum(IF(leaving_shanghai_sta=3, 1, 0)) as sumIsolation,
  232. (SELECT
  233. sum(mcr.operation_num)
  234. FROM
  235. T_Lhzx_Maintenance_Completion_Record mcr
  236. LEFT JOIN (
  237. select maintenance_company_id,section_id,max(create_date) as maxCreateDate
  238. FROM T_Lhzx_Maintenance_Completion_Record
  239. where del_flg=0
  240. GROUP BY maintenance_company_id,section_id
  241. ) max on mcr.section_id = max.section_id and mcr.maintenance_company_id = max.maintenance_company_id
  242. left join T_Lhzx_Section TLS on mcr.section_id = TLS.id
  243. WHERE mcr.create_date = max.maxCreateDate
  244. <if test="sumall.maintenanceCompanyId!=null">
  245. and mcr.maintenance_company_id=#{sumall.maintenanceCompanyId}
  246. </if>
  247. <if test="sumall.sectionName!=null and sumall.sectionName!=''">
  248. and mcr.section_name like concat('%',#{sumall.sectionName},'%')
  249. </if>
  250. <if test="sumall.maintenanceCompanyName!=null and sumall.maintenanceCompanyName!=''">
  251. and maintenance_company_name like concat('%',#{sumall.maintenanceCompanyName},'%')
  252. </if>
  253. <if test="sumall.sectionType!=null">
  254. and section_type =(#{sumall.sectionType})
  255. </if> ) as sumOnJob
  256. from
  257. (SELECT
  258. e.*,
  259. section_id
  260. FROM
  261. T_Lhzx_Employee e
  262. LEFT JOIN T_Lhzx_Employee_Section es ON e.id = es.employee_id
  263. where e.del_flg=0
  264. and e.emp_sta=0
  265. ) AS se
  266. LEFT JOIN T_Lhzx_Section s ON se.section_id = s.id
  267. where
  268. se.del_flg=0
  269. and s.del_flg=0
  270. <if test="sumall.maintenanceCompanyId!=null and sumall.maintenanceCompanyId!=''">
  271. and maintenance_company_id=#{sumall.maintenanceCompanyId}
  272. </if>
  273. <if test="sumall.maintenanceCompanyName!=null and sumall.maintenanceCompanyName!=''">
  274. and maintenance_company_name like concat('%',#{sumall.maintenanceCompanyName},'%')
  275. </if>
  276. <if test="sumall.sectionName!=null and sumall.sectionName!=''">
  277. and section_name like concat('%',#{sumall.sectionName},'%')
  278. </if>
  279. LIMIT 1
  280. </select>
  281. <select id="countManager" resultType="java.lang.Integer">
  282. select count(*)
  283. from T_Lhzx_Employee e
  284. left join
  285. T_Lhzx_Employee_Section es
  286. ON e.id = es.employee_id
  287. where section_id = #{sectionId}
  288. and job_name = '项目经理'
  289. and maintenance_company_id = #{maintenanceCompanyId}
  290. </select>
  291. <select id="residue" resultType="com.yt.zhylplat.moduleLhzx.employee.entity.TLhzxEmployee">
  292. select e.real_name,
  293. e.tel_phone
  294. from T_Lhzx_Employee e
  295. left join
  296. T_Lhzx_Employee_Section es
  297. ON e.id = es.employee_id
  298. where es.section_id = #{sectionId}
  299. and e.job_name = '项目经理'
  300. and e.maintenance_company_id = #{maintenanceCompanyId}
  301. and e.del_flg = 0
  302. and es.del_flg = 0
  303. </select>
  304. <select id="findBySectionIdAndMaintenanceCompanyId"
  305. resultType="com.yt.zhylplat.moduleLhzx.employee.entity.TLhzxEmployee">
  306. SELECT id,
  307. real_name,
  308. tel_phone
  309. FROM (SELECT * FROM T_Lhzx_Employee WHERE maintenance_company_id = #{maintenanceCompanyId} and del_flg = 0) t
  310. LEFT JOIN (SELECT employee_id
  311. FROM T_Lhzx_Employee_Section
  312. WHERE section_id = #{sectionId}
  313. and del_flg = 0) t1
  314. ON t.id = t1.employee_id
  315. WHERE t.job_name = '项目经理'
  316. AND t.real_name not in (SELECT DISTINCT project_manager
  317. FROM T_Lhzx_Road_Section_Maintenance_Company
  318. WHERE maintenance_company_id = #{maintenanceCompanyId}
  319. and del_flg = 0)
  320. </select>
  321. <select id="sectionTypePage"
  322. resultType="com.yt.zhylplat.moduleLhzx.road.entity.TLhzxRoadSectionMaintenanceCompany">
  323. SELECT
  324. s.section_type as sectionType,
  325. sum( IF ( emp_type = 0, 1, 0 )) AS managerCount,
  326. sum( IF ( emp_type != 0, 1, 0 )) AS workerCount,
  327. sum( IF ( leaving_shanghai_sta = 0, 1, 0 )) AS sumOnSh,
  328. sum( IF ( leaving_shanghai_sta = 1, 1, 0 )) AS sumLeaveSh,
  329. sum( IF ( leaving_shanghai_sta = 2, 1, 0 )) AS sumBackSh,
  330. sum( IF ( leaving_shanghai_sta = 3, 1, 0 )) AS sumIsolation,
  331. sum( IF ( emp_change_date = CURDATE() AND emp_sta = 1, 1, 0 )) AS leaveCount,
  332. sum( IF ( emp_change_date = CURDATE() AND emp_sta = 0, 1, 0 )) AS entryCount,
  333. IF(temp.operation_num is null, 0, temp.operation_num) as sumOnJob
  334. FROM
  335. T_Lhzx_Employee e
  336. LEFT JOIN T_Lhzx_Employee_Section es ON e.id = es.employee_id
  337. LEFT JOIN T_Lhzx_Section s ON es.section_id = s.id
  338. LEFT JOIN (
  339. SELECT
  340. max.section_type as section_type,
  341. sum(IF(mcr.operation_num is null, 0, mcr.operation_num)) as operation_num
  342. from
  343. T_Lhzx_Maintenance_Completion_Record mcr
  344. LEFT JOIN (
  345. SELECT
  346. r.maintenance_company_id,
  347. r.section_id,
  348. s.section_type,
  349. max( r.create_date ) AS maxCreateDate
  350. FROM
  351. T_Lhzx_Maintenance_Completion_Record r
  352. LEFT JOIN T_Lhzx_Section s ON r.section_id = s.id
  353. WHERE
  354. r.del_flg = 0
  355. GROUP BY
  356. section_type,
  357. r.maintenance_company_id,
  358. r.section_id
  359. ) max ON mcr.section_id = max.section_id AND mcr.maintenance_company_id = max.maintenance_company_id
  360. WHERE
  361. mcr.create_date = max.maxCreateDate
  362. GROUP BY
  363. max.section_type
  364. ) temp on s.section_type = temp.section_type
  365. WHERE
  366. e.del_flg = 0
  367. and
  368. s.section_type is not null
  369. GROUP BY
  370. s.section_type,
  371. temp.operation_num
  372. </select>
  373. <select id="selectEmployeePage" resultType="com.yt.zhylplat.moduleLhzx.employee.vo.TLhzxEmployeeVO">
  374. select
  375. s.section_name,
  376. e.maintenance_company_name,
  377. e.real_name,
  378. e.job_name,
  379. e.job_title,
  380. e.sex,
  381. e.tel_phone
  382. from
  383. T_Lhzx_Employee e
  384. left join
  385. T_Lhzx_Employee_Section es on e.id = es.employee_id
  386. left join
  387. T_Lhzx_Section s on s.id = es.section_id
  388. <where>
  389. and
  390. e.del_flg=0
  391. and
  392. es.del_flg = 0
  393. <if test="employee.empType != null and employee.empType == 0">
  394. and e.emp_type = 0
  395. </if>
  396. <if test="employee.empType != null and employee.empType != 0">
  397. and find_in_set(e.emp_type, '1, 2')
  398. </if>
  399. <if test="employee.sectionName != null and employee.sectionName != ''">
  400. and s.section_name like concat('%', #{employee.sectionName}, '%')
  401. </if>
  402. <if test="employee.maintenanceCompanyName != null and employee.maintenanceCompanyName != ''">
  403. and e.maintenance_company_name like concat('%', #{employee.maintenanceCompanyName}, '%')
  404. </if>
  405. </where>
  406. order by
  407. s.id, e.maintenance_company_id, e.create_date desc
  408. </select>
  409. <select id="employeeStatus"
  410. resultType="com.yt.zhylplat.moduleLhzx.road.entity.TLhzxRoadSectionMaintenanceCompany">
  411. SELECT DISTINCT
  412. emp.section_id as sectionId,
  413. emp.section_name,
  414. emp.maintenance_company_id,
  415. emp.maintenance_company_name,
  416. emp.section_type as sectionType,
  417. project_manager AS projectManager,
  418. project_manager_tel,
  419. charge_leader AS chargeLeader,
  420. charge_leader_tel AS chargeLeaderTel,
  421. maneger AS managerCount,
  422. worker AS workerCount,
  423. emp.OnSh as sumOnSh,
  424. emp.LeaveSh as sumLeaveSh,
  425. emp.BackSh as sumBackSh,
  426. emp.Isolation as sumIsolation,
  427. emp.leavecount as leaveCount,
  428. emp.entrycount as entryCount,
  429. (select operation_num FROM T_Lhzx_Maintenance_Completion_Record where del_flg=0 and section_id = emp.section_id and maintenance_company_id = emp.maintenance_company_id order by create_date desc limit 1) as operation_num
  430. FROM (
  431. SELECT
  432. es.section_id,
  433. s.section_name,
  434. maintenance_company_id,
  435. maintenance_company_name,
  436. s.section_type,
  437. sum(IF(emp_type=0, 1, 0)) AS maneger,
  438. sum(IF(emp_type!=0, 1, 0)) AS worker,
  439. sum(IF(leaving_shanghai_sta=0,1,0)) as OnSh,
  440. sum(IF(leaving_shanghai_sta=1, 1, 0)) as LeaveSh,
  441. sum(IF(leaving_shanghai_sta=2, 1, 0)) as BackSh,
  442. sum(IF(leaving_shanghai_sta=3, 1, 0)) as Isolation,
  443. sum(if(emp_change_date = CURDATE() and emp_sta=1,1,0)) as leavecount,
  444. sum(if(emp_change_date = CURDATE() and emp_sta=0,1,0)) as entrycount
  445. FROM T_Lhzx_Employee e
  446. left join T_Lhzx_Employee_Section es on e.id = es.employee_id
  447. left join T_Lhzx_Section s on es.section_id = s.id
  448. WHERE e.del_flg = 0
  449. and es.section_id is not null
  450. GROUP BY
  451. es.section_id,
  452. s.section_name,
  453. maintenance_company_id,
  454. maintenance_company_name
  455. ) AS emp
  456. LEFT JOIN (
  457. SELECT DISTINCT section_id,
  458. maintenance_company_id,
  459. project_manager,
  460. project_manager_tel,
  461. charge_leader,
  462. charge_leader_tel
  463. FROM T_Lhzx_Road_Section_Maintenance_Company
  464. WHERE del_flg = 0
  465. ) AS rsmc ON emp.maintenance_company_id = rsmc.maintenance_company_id and rsmc.section_id = emp.section_id
  466. ORDER BY
  467. emp.section_type, emp.section_id asc,emp.maintenance_company_id asc
  468. </select>
  469. </mapper>