UserServiceDaoImplMapper.xml 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504
  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="userServiceDaoImpl">
  6. <resultMap type="com.java110.entity.user.Cust" id="custMap">
  7. <id column="custId" jdbcType="VARCHAR" property="custId"/>
  8. <result column="name" jdbcType="VARCHAR" property="name"/>
  9. <result column="email" jdbcType="VARCHAR" property="email"/>
  10. <result column="cellphone" jdbcType="VARCHAR" property="cellphone"/>
  11. <result column="realName" jdbcType="VARCHAR" property="realName"/>
  12. <result column="sex" jdbcType="VARCHAR" property="sex"/>
  13. <result column="password" jdbcType="VARCHAR" property="password"/>
  14. <result column="lanId" jdbcType="VARCHAR" property="lanId"/>
  15. <result column="custAdress" jdbcType="VARCHAR" property="custAdress"/>
  16. <result column="custType" jdbcType="VARCHAR" property="custType"/>
  17. <result column="openId" jdbcType="VARCHAR" property="openId"/>
  18. <!-- 一对多关系 -->
  19. <!-- <collection property="stus" resultMap="Student.StudentResult"></collection> -->
  20. <collection property="custAttrs" javaType="com.java110.entity.user.CustAttr">
  21. <id property="custId" column="custId"/>
  22. <result property="attrCd" column="attrCd"/>
  23. <result property="value" column="value"/>
  24. </collection>
  25. </resultMap>
  26. <!--根据用户Id查询用户角色
  27. <select id="findRolesByUserId" resultType="SysRole">
  28. SELECT
  29. r.*
  30. FROM
  31. t_role r,
  32. t_user_role ur
  33. WHERE ur.uid = #{userId}
  34. AND ur.roleId = r.roleId
  35. AND ur.status_cd = '1'
  36. </select>
  37. -->
  38. <!--保存数据至过程表 bo_cust 中 -->
  39. <insert id="saveDataToBoCust" parameterType="com.java110.entity.user.BoCust">
  40. <![CDATA[
  41. insert into bo_cust(boId,custId,name,email,cellphone,realName,sex,password,lanId,custAdress,custType,openId,state)
  42. values(#{boId},#{custId},#{name},#{email},#{cellphone},#{realName},#{sex},#{password},#{lanId},#{custAdress},#{custType},#{openId},#{state})
  43. ]]>
  44. </insert>
  45. <!-- 保存数据至过程表bo_cust_attr 中-->
  46. <insert id="saveDataToBoCustAttr" parameterType="com.java110.entity.user.BoCustAttr">
  47. <![CDATA[
  48. insert into bo_cust_attr(boId,custId,attrCd,value,state)
  49. values(#{boId},#{custId},#{attrCd},#{value},#{state})
  50. ]]>
  51. </insert>
  52. <!-- 保存 实例客户信息 cust -->
  53. <insert id="saveDataToCust" parameterType="com.java110.entity.user.Cust">
  54. <![CDATA[
  55. insert into cust(custId,name,email,cellphone,realName,sex,password,lanId,custAdress,custType,openId,status_cd)
  56. values(#{custId},#{name},#{email},#{cellphone},#{realName},#{sex},#{password},#{lanId},#{custAdress},#{custType},#{openId},#{status_cd})
  57. ]]>
  58. </insert>
  59. <!-- 删除实例客户信息 cust -->
  60. <insert id="deleteDataToCust" parameterType="com.java110.entity.user.Cust">
  61. <![CDATA[
  62. delete * from cust c where c.custId = #{custId}
  63. ]]>
  64. </insert>
  65. <!-- 保存 实例客户属性信息 cust_attr -->
  66. <insert id="saveDataToCustAttr" parameterType="com.java110.entity.user.CustAttr">
  67. <![CDATA[
  68. insert into cust_attr(custId,attrCd,value,status_cd)
  69. values(#{custId},#{attrCd},#{value},#{status_cd})
  70. ]]>
  71. </insert>
  72. <!-- 删除实例客户信息 cust -->
  73. <update id="deleteDataToCustAttr" parameterType="com.java110.entity.user.CustAttr">
  74. delete * from cust_attr ct where 1=1
  75. <if test="custId != null and custId != ''">
  76. and ct.custId = #{custId}
  77. </if>
  78. <if test="attrCd != null and attrCd != ''">
  79. and ct.attrCd = #{attrCd}
  80. </if>
  81. </update>
  82. <!--根据客户ID 查询客户信息,其中包括 cust 和custAttr 数据-->
  83. <select id="queryDataToCust" parameterType="com.java110.entity.user.Cust" resultMap="custMap">
  84. select c.custId,c.name,c.email,c.cellphone,c.realName,c.sex,c.password,c.lanId,c.custAdress,c.custType,c.openId,
  85. ca.custId,ca.attrCd,ca.value
  86. from cust c, cust_attr ca where c.custId= ca.custId
  87. <if test="custId != null and custId != ''">
  88. and c.custId = #{custId}
  89. </if>
  90. <if test="versionId != null and versionId != ''">
  91. and c.versionId = #{versionId}
  92. </if>
  93. and c.status_cd = '0'
  94. </select>
  95. <!-- 查询客户过程数据 -->
  96. <select id="queryBoCust" parameterType="com.java110.entity.user.BoCust" resultType="com.java110.entity.user.BoCust">
  97. select bc.boId,bc.custId,bc.name,bc.email,bc.cellphone,bc.realName,bc.sex,bc.password,bc.lanId,bc.custAdress,bc.custType,bc.openId,bc.create_dt
  98. from bo_cust bc where 1=1
  99. <if test="boId != null and boId != ''">
  100. and bc.boId = #{boId}
  101. </if>
  102. <if test="custId != null and custId != ''">
  103. and bc.custId = #{custId}
  104. </if>
  105. <if test="versionId != null and versionId != ''">
  106. and c.versionId = #{versionId}
  107. </if>
  108. and bc.state in ('ADD','DEL','KIP')
  109. <if test="create_dt != null and create_dt != ''">
  110. order by bc.create_dt desc
  111. </if>
  112. </select>
  113. <!-- 查询客户属性过程表-->
  114. <select id="queryBoCustAttr" parameterType="com.java110.entity.user.BoCustAttr" resultType="com.java110.entity.user.BoCustAttr">
  115. select bca.boId,bca.custId,bca.attrCd,bca.value,bca.state,bca.create_dt from bo_cust_attr bca where 1=1
  116. <if test="boId !=null and boId != ''">
  117. and bca.boId = #{boId}
  118. </if>
  119. <if test="custId != null and custId != ''">
  120. and bca.custId = #{custId}
  121. </if>
  122. <if test="versionId != null and versionId != ''">
  123. and bca.versionId = #{versionId}
  124. </if>
  125. <if test="create_dt != null and create_dt != ''">
  126. order by bca.create_dt desc
  127. </if>
  128. </select>
  129. <!-- 查询客户属性信息 -->
  130. <select id="queryDataToCustAttr" parameterType="com.java110.entity.user.CustAttr" resultType="com.java110.entity.user.CustAttr">
  131. select * from cust_attr ca where 1=1
  132. <if test="custId != null and custId != ''">
  133. and ca.custId = #{custId}
  134. </if>
  135. <if test="versionId != null and versionId != ''">
  136. and ca.versionId = #{versionId}
  137. </if>
  138. <if test="attrCd != null and attrCd != ''">
  139. and ca.attrCd = #{attrCd}
  140. </if>
  141. and status_cd = '0'
  142. </select>
  143. <!-- 保存用户信息 -->
  144. <insert id="saveBusinessUserInfo" parameterType="map">
  145. insert into business_user(b_id,user_id,name,email,address,password,location_cd,age,sex,tel,level_cd,operate)
  146. values(#{bId},#{userId},#{name},#{email},#{address},#{password},#{locationCd},#{age},#{sex},#{tel},#{levelCd},#{operate})
  147. </insert>
  148. <!-- 保存用户属性 -->
  149. <insert id="saveBusinessUserAttr" parameterType="map">
  150. insert into business_user_attr(b_id,user_id,attr_id,spec_cd,value,operate)
  151. values(#{bId},#{userId},#{attrId},#{specCd},#{value},#{operate})
  152. </insert>
  153. <!-- 实例数据 -->
  154. <insert id="saveUserInfoInstance" parameterType="map">
  155. insert into u_user(user_id,name,email,address,password,location_cd,age,sex,tel,level_cd,b_id,status_cd)
  156. select bu.user_id,bu.name,bu.email,bu.address,bu.password,bu.location_cd,bu.age,bu.sex,bu.tel,bu.level_cd,bu.b_id,'0' from business_user bu where bu.operate = 'ADD' and bu.b_id=#{b_id}
  157. </insert>
  158. <insert id="saveUserAttrInstance" parameterType="map">
  159. insert into u_user_attr(attr_id,user_id,spec_cd,value,b_id,status_cd)
  160. select bua.attr_id,bua.user_id,bua.spec_cd,bua.value,bua.b_id,'0' from business_user_attr bua where bua.operate='ADD' and bua.b_id=#{b_id}
  161. </insert>
  162. <update id="updateUserInfoInstance" parameterType="map">
  163. update u_user u set u.status_cd = #{statusCd}
  164. <if test="newBId != null and newBId != ''">
  165. ,u.b_id = #{newBId}
  166. </if>
  167. <if test="name !=null and name != ''">
  168. ,u.name= #{name}
  169. </if>
  170. <if test="email !=null and email != ''">
  171. ,u.email= #{email}
  172. </if>
  173. <if test="address !=null and address != ''">
  174. ,u.address= #{address}
  175. </if>
  176. <if test="password !=null and password != ''">
  177. ,u.password= #{password}
  178. </if>
  179. <if test="locationCd !=null and locationCd != ''">
  180. ,u.location_cd= #{locationCd}
  181. </if>
  182. <if test="age !=null and age != ''">
  183. ,u.age= #{age}
  184. </if>
  185. <if test="sex !=null and sex != ''">
  186. ,u.sex= #{sex}
  187. </if>
  188. <if test="tel !=null and tel != ''">
  189. ,u.tel= #{tel}
  190. </if>
  191. where 1 = 1
  192. <if test="bId != null and bId != ''">
  193. and u.b_id = #{bId}
  194. </if>
  195. <if test="userId != null and userId !=''">
  196. and u.user_id = #{userId}
  197. </if>
  198. <if test="attrId != null and attrId != ''">
  199. and u.attr_id = #{attrId}
  200. </if>
  201. </update>
  202. <update id="updateUserAttrInstance" parameterType="map">
  203. update u_user_attr ua set ua.status_cd = #{statusCd} where 1 = 1
  204. <if test="bId != null and bId != ''">
  205. and ua.b_id = #{bId}
  206. </if>
  207. <if test="userId != null and userId !=''">
  208. and ua.user_id = #{userId}
  209. </if>
  210. </update>
  211. <!-- 查询用户信息 Business -->
  212. <select id="queryBusinessUserInfo" parameterType="map" resultType="map">
  213. select u.user_id,u.name,u.email,u.address,u.password,u.location_cd,
  214. u.age,u.sex,u.tel,u.level_cd,u.b_id,u.operate
  215. from business_user u where 1 = 1
  216. <if test="operate != null and operate != ''">
  217. and u.operate = #{operate}
  218. </if>
  219. <if test="bId != null and bId !=''">
  220. and u.b_id = #{bId}
  221. </if>
  222. <if test="userId != null and userId != ''">
  223. and u.user_id = #{userId}
  224. </if>
  225. </select>
  226. <!-- 查询用户属性信息 Business-->
  227. <select id="queryBusinessUserInfoAttrs" parameterType="map" resultType="map">
  228. select u.attr_id,u.user_id,u.spec_cd,u.value,u.b_id,u.operate
  229. from business_user_attr u where 1 = 1
  230. <if test="operate != null and operate != ''">
  231. and u.operate = #{operate}
  232. </if>
  233. <if test="bId != null and bId !=''">
  234. and u.b_id = #{bId}
  235. </if>
  236. <if test="userId != null and userId != ''">
  237. and u.user_id = #{userId}
  238. </if>
  239. <if test="attrId != null and attrId != ''">
  240. and u.attr_id = #{attrId}
  241. </if>
  242. </select>
  243. <!-- 查询用户信息 -->
  244. <select id="queryUserInfo" parameterType="map" resultType="map">
  245. select u.user_id, u.user_id userId,u.name,u.name userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
  246. u.age,u.sex,u.tel,u.level_cd,u.b_id
  247. from u_user u where 1= 1
  248. <if test="bId != null and bId !=''">
  249. and u.b_id = #{bId}
  250. </if>
  251. <if test="userId != null and userId != ''">
  252. and u.user_id = #{userId}
  253. </if>
  254. <if test="statusCd !=null and statusCd != ''">
  255. and u.status_cd = #{statusCd}
  256. </if>
  257. <if test="userIds != null and userIds != null">
  258. and u.user_id in
  259. <foreach collection="userIds" item="item" open="(" close=")" separator=",">
  260. #{item}
  261. </foreach>
  262. </if>
  263. </select>
  264. <!-- 查询用户属性信息 -->
  265. <select id="queryUserInfoAttrs" parameterType="map" resultType="map">
  266. select u.attr_id,u.user_id,u.spec_cd,u.value,u.b_id
  267. from u_user_attr u where u.status_cd = '0'
  268. <if test="bId != null and bId !=''">
  269. and u.b_id = #{bId}
  270. </if>
  271. <if test="userId != null and userId != ''">
  272. and u.user_id = #{userId}
  273. </if>
  274. <if test="attrId != null and attrId != ''">
  275. and u.attr_id = #{attrId}
  276. </if>
  277. </select>
  278. <!--保存用户地址信息 add by wuxw 2018-06-29 -->
  279. <insert id="saveBusinessUserAddress" parameterType="map">
  280. insert into business_user_address(address_id,b_id,user_id,tel,postal_code,address,is_default,operate)
  281. values(#{addressId},#{bId},#{userId},#{tel},#{postalCode},#{address},#{isDefault},#{operate})
  282. </insert>
  283. <!-- 查询用户地址信息 add by wuxw 2018-06-29-->
  284. <select id="queryBusinessUserAddress" parameterType="map" resultType="map">
  285. select ua.address_id,ua.b_id,ua.user_id,ua.tel,ua.postal_code,ua.address,ua.is_default,ua.operate
  286. from business_user_address ua where 1 = 1
  287. <if test="operate != null and operate != ''">
  288. and ua.operate = #{operate}
  289. </if>
  290. <if test="bId != null and bId !=''">
  291. and ua.b_id = #{bId}
  292. </if>
  293. <if test="userId != null and userId != ''">
  294. and ua.user_id = #{userId}
  295. </if>
  296. </select>
  297. <!-- 保存用户地址 Business 数据到 Instance add by wuxw 2018-06-29 -->
  298. <insert id="saveUserAddressInstance" parameterType="map">
  299. insert into u_user_address(address_id,b_id,user_id,tel,postal_code,address,is_default,status_cd)
  300. select ua.address_id,ua.b_id,ua.user_id,ua.tel,ua.postal_code,ua.address,ua.is_default,'0'
  301. from business_user_address ua where 1 = 1
  302. ua.operate = 'ADD' and ua.b_id=#{b_id}
  303. </insert>
  304. <!-- 作废用户地址信息数据 add by wuxw 2018-06-29-->
  305. <update id="updateUserAddressInstance" parameterType="map">
  306. update u_user_address ua set ua.status_cd = #{statusCd} where 1 = 1
  307. <if test="bId != null and bId != ''">
  308. and ua.b_id = #{bId}
  309. </if>
  310. <if test="userId != null and userId !=''">
  311. and ua.user_id = #{userId}
  312. </if>
  313. <if test="addressId != null and addressId != ''">
  314. and ua.address_id = #{addressId}
  315. </if>
  316. </update>
  317. <!--保存用户打标信息 add by wuxw 2018-06-29 -->
  318. <insert id="saveBusinessUserTag" parameterType="map">
  319. insert into business_user_tag(tag_id,b_id,user_id,tag_cd,remark,operate)
  320. values(#{tagId},#{bId},#{userId},#{tagCd},#{remark},#{operate})
  321. </insert>
  322. <!-- 查询用户地址信息 add by wuxw 2018-06-29-->
  323. <select id="queryBusinessUserTag" parameterType="map" resultType="map">
  324. select ut.tag_id,ut.b_id,ut.user_id,ut.tag_cd,ut.remark,ut.operate
  325. from business_user_tag ut where 1 = 1
  326. <if test="operate != null and operate != ''">
  327. and ut.operate = #{operate}
  328. </if>
  329. <if test="bId != null and bId !=''">
  330. and ut.b_id = #{bId}
  331. </if>
  332. <if test="userId != null and userId != ''">
  333. and ut.user_id = #{userId}
  334. </if>
  335. </select>
  336. <!-- 保存用户地址 Business 数据到 Instance add by wuxw 2018-06-29 -->
  337. <insert id="saveUserTagInstance" parameterType="map">
  338. insert into u_user_tag(tag_id,b_id,user_id,tag_cd,remark,status_cd)
  339. select ut.tag_id,ut.b_id,ut.user_id,ut.tag_cd,ut.remark,'0'
  340. from business_user_tag ut where 1 = 1
  341. ut.operate = 'ADD' and ut.b_id=#{b_id}
  342. </insert>
  343. <!-- 作废用户地址信息数据 add by wuxw 2018-06-29-->
  344. <update id="updateUserTagInstance" parameterType="map">
  345. update u_user_tag ut set ut.status_cd = #{statusCd} where 1 = 1
  346. <if test="bId != null and bId != ''">
  347. and ut.b_id = #{bId}
  348. </if>
  349. <if test="userId != null and userId !=''">
  350. and ut.user_id = #{userId}
  351. </if>
  352. <if test="addressId != null and addressId != ''">
  353. and ut.address_id = #{tagId}
  354. </if>
  355. </update>
  356. <!--保存用户证件信息 add by wuxw 2018-06-29 -->
  357. <insert id="saveBusinessUserCredentials" parameterType="map">
  358. insert into business_user_credentials(credentials_id,b_id,user_id,credentials_cd,value,operate)
  359. values(#{credentialsId},#{bId},#{userId},#{credentialsCd},#{value},#{operate})
  360. </insert>
  361. <!-- 查询用户地址信息 add by wuxw 2018-06-29-->
  362. <select id="queryBusinessUserCredentials" parameterType="map" resultType="map">
  363. select uc.credentials_id,uc.b_id,uc.user_id,uc.credentials_cd,uc.value,uc.operate
  364. from business_user_credentials uc where 1 = 1
  365. <if test="operate != null and operate != ''">
  366. and uc.operate = #{operate}
  367. </if>
  368. <if test="bId != null and bId !=''">
  369. and uc.b_id = #{bId}
  370. </if>
  371. <if test="userId != null and userId != ''">
  372. and uc.user_id = #{userId}
  373. </if>
  374. </select>
  375. <!-- 保存用户地址 Business 数据到 Instance add by wuxw 2018-06-29 -->
  376. <insert id="saveUserCredentialsInstance" parameterType="map">
  377. insert into u_user_credentials(credentials_id,b_id,user_id,credentials_cd,value,status_cd)
  378. select uc.credentials_id,uc.b_id,uc.user_id,uc.credentials_cd,uc.value,'0'
  379. from business_user_credentials uc where 1 = 1
  380. uc.operate = 'ADD' and uc.b_id=#{b_id}
  381. </insert>
  382. <!-- 作废用户地址信息数据 add by wuxw 2018-06-29-->
  383. <update id="updateUserCredentialsInstance" parameterType="map">
  384. update u_user_credentials uc set uc.status_cd = #{statusCd} where 1 = 1
  385. <if test="bId != null and bId != ''">
  386. and uc.b_id = #{bId}
  387. </if>
  388. <if test="userId != null and userId !=''">
  389. and uc.user_id = #{userId}
  390. </if>
  391. <if test="addressId != null and addressId != ''">
  392. and uc.credentials_id = #{credentialsId}
  393. </if>
  394. </update>
  395. <!-- 查询员工总量 -->
  396. <select id="getStaffCount" parameterType="Map" resultType="Map">
  397. select count(1) count
  398. from
  399. u_user a
  400. ,u_org uo
  401. ,u_org_staff_rel uosr
  402. where a.level_cd = '01'
  403. and a.user_id = uosr.staff_id
  404. and uosr.store_id = #{storeId}
  405. and uosr.org_id = uo.org_id
  406. <if test="parentOrgId !=null and parentOrgId != ''">
  407. and uo.parent_org_id = #{parentOrgId}
  408. </if>
  409. and a.status_cd = '0'
  410. and uo.status_cd = '0'
  411. and uosr.status_cd = '0'
  412. <if test="tel !=null and tel != ''">
  413. and a.tel= #{tel}
  414. </if>
  415. <if test="name !=null and name != ''">
  416. and a.name like contact('%',#{name},'%')
  417. </if>
  418. <if test="staffName !=null and staffName != ''">
  419. and a.name like contact('%',#{staffName},'%')
  420. </if>
  421. <if test="staffId != null and staffId !=''">
  422. and uosr.staff_id = #{staffId}
  423. </if>
  424. </select>
  425. <!-- 查询员工总量 -->
  426. <select id="getStaffs" parameterType="Map" resultType="Map">
  427. select uo.org_name,uo.org_name orgName,u.user_id, u.user_id userId,u.name,u.name userName,u.email,u.address,u.password,u.location_cd,u.location_cd locationCd,
  428. u.age,u.sex,u.tel,u.level_cd,u.b_id
  429. from
  430. u_user a
  431. ,u_org uo
  432. ,u_org_staff_rel uosr
  433. where a.level_cd = '01'
  434. and a.user_id = uosr.staff_id
  435. and uosr.store_id = #{storeId}
  436. and uosr.org_id = uo.org_id
  437. <if test="parentOrgId !=null and parentOrgId != ''">
  438. and uo.parent_org_id = #{parentOrgId}
  439. </if>
  440. and a.status_cd = '0'
  441. and uo.status_cd = '0'
  442. and uosr.status_cd = '0'
  443. <if test="tel !=null and tel != ''">
  444. and a.tel= #{tel}
  445. </if>
  446. <if test="name !=null and name != ''">
  447. and a.name like contact('%',#{name},'%')
  448. </if>
  449. <if test="staffName !=null and staffName != ''">
  450. and a.name like contact('%',#{staffName},'%')
  451. </if>
  452. <if test="staffId != null and staffId !=''">
  453. and uosr.staff_id = #{staffId}
  454. </if>
  455. <if test="page != -1 and page != null ">
  456. limit #{page}, #{row}
  457. </if>
  458. order by a.create_time desc
  459. </select>
  460. </mapper>