Guest User

Untitled

a guest
Oct 18th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.38 KB | None | 0 0
  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.  
  4. <mapper namespace="com.ncell.portal.restapi.mappers.OrganizationUnitMapper">
  5.  
  6. <resultMap type="OrganizationUnit" id="orgUnitResult">
  7. <id property="id" column="org_id" />
  8. <result property="type" column="org_type" />
  9. <result property="name" column="org_name" />
  10.  
  11. <collection property="ledBy" javaType="Employee">
  12. <id property="id" column="head_id" />
  13. <result property="firstName" column="head_fname" />
  14. <result property="middleName" column="head_mname" />
  15. <result property="lastName" column="head_lname" />
  16. <result property="email" column="head_email" />
  17. <result property="profileImage" column="head_proimage" />
  18. <result property="designation" column="head_designation" />
  19. </collection>
  20.  
  21. <collection property="leafUnits" javaType="List" ofType="Employee">
  22. <id property="id" column="leaf_id" />
  23. <result property="firstName" column="leaf_fname" />
  24. <result property="middleName" column="leaf_mname" />
  25. <result property="lastName" column="leaf_lname" />
  26. <result property="email" column="leaf_email" />
  27. <result property="profileImage" column="leaf_proimage" />
  28. <result property="designation" column="leaf_designation" />
  29. </collection>
  30. </resultMap>
  31.  
  32. <select id="searchOrgUnit" resultMap="orgUnitResult" resultType="OrganizationUnit">
  33. SELECT
  34. OU.id AS org_id,
  35. OU.type AS org_type,
  36. OU.name AS org_name,
  37. U.id AS
  38. head_id,
  39. U.first_name AS head_fname,
  40. U.middle_name AS head_mname,
  41. U.last_name AS head_lname,
  42. U.email AS head_email,
  43. U.profile_image AS
  44. head_proimage,
  45. U.designation AS head_designation
  46. FROM
  47. portal.org_unit OU
  48. LEFT OUTER JOIN
  49. portal.org_unit_type OT ON OT.id = OU.type
  50. LEFT OUTER
  51. JOIN
  52. portal.user U ON U.id = OU.led_by
  53. WHERE
  54. OU.id = #{orgUnitId};
  55. </select>
  56.  
  57.  
  58. <select id="getOrgChildUnits" resultMap="orgUnitResult"
  59. resultType="OrganizationUnit">
  60. SELECT
  61. OU.id AS org_id,
  62. OU.type AS org_type,
  63. OU.name AS
  64. org_name,
  65. U.id AS
  66. head_id,
  67. U.first_name AS head_fname,
  68. U.middle_name AS
  69. head_mname,
  70. U.last_name AS head_lname,
  71. U.email AS head_email,
  72. U.profile_image AS
  73. head_proimage,
  74. U.designation AS head_designation
  75. FROM
  76. portal.org_unit OU
  77. LEFT OUTER JOIN
  78. portal.org_unit_type OT ON OT.id =
  79. OU.type
  80. LEFT OUTER
  81. JOIN
  82. portal.user U ON U.id = OU.led_by
  83. WHERE
  84. OU.parent =
  85. #{orgUnitId}
  86. and
  87. not (OU.id = OU.parent);
  88. </select>
  89.  
  90. <select id="getOrgLeafUnits" resultMap="orgUnitResult"
  91. resultType="Employee">
  92. SELECT
  93. U.id AS leaf_id,
  94. U.first_name AS leaf_fname,
  95. U.middle_name AS
  96. leaf_mname,
  97. U.last_name AS leaf_lname,
  98. U.email AS
  99. leaf_email,
  100. U.profile_image AS leaf_proimage,
  101. U.designation AS
  102. leaf_designation
  103. FROM
  104. portal.user U
  105. LEFT OUTER JOIN
  106. portal.org_unit OU ON
  107. OU.id =
  108. U.org_unit
  109. WHERE
  110. U.org_unit = #{orgUnitId}
  111. AND (OU.led_by IS NULL
  112. OR
  113. OU.led_by != U.id)
  114. </select>
  115.  
  116. </mapper>
  117.  
  118. {
  119. "id": 0,
  120. "type" :0,
  121. "name":"Organization",
  122. "head":
  123. {
  124. "firstName" :"yasas",
  125. "lastName":"karunarathna",
  126. "middleName" :"gwsdvwdv",
  127. "email": "yasas@gmail.com",
  128. "profieImage": "/assets/images/profile-pics/8001800.png",
  129. "designation": "Engineer-Technology"
  130. },
  131. "childUnits": [
  132. {
  133. "id": 1,
  134. "type" :1,
  135. "name":"Department",
  136. "head": {
  137. "firstName" :"yasas",
  138. "lastName":"karunarathna",
  139. "middleName" :"gwsdvwdv",
  140. "email": "yasas@gmail.com",
  141. "profieImage": "/assets/images/profile-pics/8001800.png",
  142. "designation": "Engineer-Technology"
  143. },
  144. "childUnits": [],
  145. "leafUnits":[]
  146. },
  147. {
  148. "id": 1,
  149. "type" :1,
  150. "name":"Department",
  151. "head": {
  152. "firstName" :"yasas",
  153. "lastName":"karunarathna",
  154. "middleName" :"gwsdvwdv",
  155. "email": "yasas@gmail.com",
  156. "profieImage": "/assets/images/profile-pics/8001800.png",
  157. "designation": "Engineer-Technology"
  158. },
  159. "childUnits": [],
  160. "leafUnits":[]
  161. }
  162. ],
  163. "leafUnits":[
  164. {
  165. "firstName" :"yasas",
  166. "lastName":"karunarathna",
  167. "middleName" :"gwsdvwdv",
  168. "email": "yasas@gmail.com",
  169. "profieImage": "/assets/images/profile-pics/8001800.png",
  170. "designation": "Engineer-Technology"
  171. },
  172. {
  173. "firstName" :"yasas",
  174. "lastName":"karunarathna",
  175. "middleName" :"gwsdvwdv",
  176. "email": "yasas@gmail.com",
  177. "profieImage": "/assets/images/profile-pics/8001800.png",
  178. "designation": "Engineer-Technology"
  179. }
  180. ]
  181. }
  182.  
  183. public class OrganizationUnit {
  184.  
  185. private int id;
  186. private int type;
  187. private String name;
  188. private Employee ledBy;
  189. private List<OrganizationUnit> childUnits;
  190. private List<Employee> leafUnits;
  191.  
  192. public OrganizationUnit() {
  193. super();
  194. // TODO Auto-generated constructor stub
  195. }
  196.  
  197. public OrganizationUnit(int id, int type, String name, Employee ledBy, List<OrganizationUnit> childUnits,
  198. List<Employee> leafUnits) {
  199. super();
  200. this.id = id;
  201. this.type = type;
  202. this.name = name;
  203. this.ledBy = ledBy;
  204. this.childUnits = childUnits;
  205. this.leafUnits = leafUnits;
  206. }
  207.  
  208. public int getId() {
  209. return id;
  210. }
  211.  
  212. public void setId(int id) {
  213. this.id = id;
  214. }
  215.  
  216. public int getType() {
  217. return type;
  218. }
  219.  
  220. public void setType(int type) {
  221. this.type = type;
  222. }
  223.  
  224. public String getName() {
  225. return name;
  226. }
  227.  
  228. public void setName(String name) {
  229. this.name = name;
  230. }
  231.  
  232. public Employee getLedBy() {
  233. return ledBy;
  234. }
  235.  
  236. public void setLedBy(Employee ledBy) {
  237. this.ledBy = ledBy;
  238. }
  239.  
  240. public List<OrganizationUnit> getChildUnits() {
  241. return childUnits;
  242. }
  243.  
  244. public void setChildUnits(List<OrganizationUnit> childUnits) {
  245. this.childUnits = childUnits;
  246. }
  247.  
  248. public List<Employee> getLeafUnits() {
  249. return leafUnits;
  250. }
  251.  
  252. public void setLeafUnits(List<Employee> leafUnits) {
  253. this.leafUnits = leafUnits;
  254. }
  255.  
  256. }
  257.  
  258. public class Employee {
  259. private int id;
  260. private String firstName;
  261. private String middleName;
  262. private String lastName;
  263. private String designation;
  264. private String department;
  265. private String email;
  266. private String mobile;
  267. private String profileImage;
  268. private int orgUnit;
  269.  
  270. public Employee() {
  271. super();
  272. }
  273.  
  274. public Employee(int id, String firstName, String middleName, String lastName, String designation, String department,
  275. String email, String mobile, String profileImage, int orgUnit) {
  276. super();
  277. this.id = id;
  278. this.firstName = firstName;
  279. this.middleName = middleName;
  280. this.lastName = lastName;
  281. this.designation = designation;
  282. this.department = department;
  283. this.email = email;
  284. this.mobile = mobile;
  285. this.profileImage = profileImage;
  286. this.orgUnit = orgUnit;
  287. }
  288.  
  289. public int getId() {
  290. return id;
  291. }
  292.  
  293. public void setId(int id) {
  294. this.id = id;
  295. }
  296.  
  297. public String getFirstName() {
  298. return firstName;
  299. }
  300.  
  301. public void setFirstName(String firstName) {
  302. this.firstName = firstName;
  303. }
  304.  
  305. public String getMiddleName() {
  306. return middleName;
  307. }
  308.  
  309. public void setMiddleName(String middleName) {
  310. this.middleName = middleName;
  311. }
  312.  
  313. public String getLastName() {
  314. return lastName;
  315. }
  316.  
  317. public void setLastName(String lastName) {
  318. this.lastName = lastName;
  319. }
  320.  
  321. public String getDesignation() {
  322. return designation;
  323. }
  324.  
  325. public void setDesignation(String designation) {
  326. this.designation = designation;
  327. }
  328.  
  329. public String getDepartment() {
  330. return department;
  331. }
  332.  
  333. public void setDepartment(String department) {
  334. this.department = department;
  335. }
  336.  
  337. public String getEmail() {
  338. return email;
  339. }
  340.  
  341. public void setEmail(String email) {
  342. this.email = email;
  343. }
  344.  
  345. public String getMobile() {
  346. return mobile;
  347. }
  348.  
  349. public void setMobile(String mobile) {
  350. this.mobile = mobile;
  351. }
  352.  
  353. public String getProfileImage() {
  354. return profileImage;
  355. }
  356.  
  357. public void setProfileImage(String profileImage) {
  358. this.profileImage = profileImage;
  359. }
  360.  
  361. public int getOrgUnit() {
  362. return orgUnit;
  363. }
  364.  
  365. public void setOrgUnit(int orgUnit) {
  366. this.orgUnit = orgUnit;
  367. }
  368.  
  369. }
Add Comment
Please, Sign In to add comment