KwsEnterpriseDao.xml 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  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.sckw.system.dao.KwsEnterpriseDao">
  4. <resultMap id="BaseResultMap" type="com.sckw.system.model.KwsEnterprise">
  5. <id column="id" jdbcType="BIGINT" property="id" />
  6. <result column="firm_name" jdbcType="VARCHAR" property="firmName" />
  7. <result column="code" jdbcType="VARCHAR" property="code" />
  8. <result column="contacts" jdbcType="VARCHAR" property="contacts" />
  9. <result column="phone" jdbcType="VARCHAR" property="phone" />
  10. <result column="legal_name" jdbcType="VARCHAR" property="legalName" />
  11. <result column="legal_phone" jdbcType="VARCHAR" property="legalPhone" />
  12. <result column="head" jdbcType="VARCHAR" property="head" />
  13. <result column="integral" jdbcType="INTEGER" property="integral" />
  14. <result column="balance" jdbcType="DECIMAL" property="balance" />
  15. <result column="experience" jdbcType="INTEGER" property="experience" />
  16. <result column="member_level" jdbcType="INTEGER" property="memberLevel" />
  17. <result column="reg_time" jdbcType="TIMESTAMP" property="regTime" />
  18. <result column="reg_source" jdbcType="VARCHAR" property="regSource" />
  19. <result column="org_code" jdbcType="VARCHAR" property="orgCode" />
  20. <result column="city_code" jdbcType="INTEGER" property="cityCode" />
  21. <result column="detail_address" jdbcType="VARCHAR" property="detailAddress" />
  22. <result column="city_name" jdbcType="VARCHAR" property="cityName" />
  23. <result column="lat" jdbcType="VARCHAR" property="lat" />
  24. <result column="lng" jdbcType="VARCHAR" property="lng" />
  25. <result column="approval" jdbcType="INTEGER" property="approval" />
  26. <result column="approval_time" jdbcType="TIMESTAMP" property="approvalTime" />
  27. <result column="manager" jdbcType="BIGINT" property="manager" />
  28. <result column="remark" jdbcType="VARCHAR" property="remark" />
  29. <result column="status" jdbcType="INTEGER" property="status" />
  30. <result column="create_by" jdbcType="BIGINT" property="createBy" />
  31. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  32. <result column="update_by" jdbcType="BIGINT" property="updateBy" />
  33. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  34. <result column="del_flag" jdbcType="INTEGER" property="delFlag" />
  35. </resultMap>
  36. <sql id="Base_Column_List">
  37. id, firm_name, code, contacts, phone, legal_name, legal_phone, head, integral,
  38. balance, experience, member_level, reg_time, reg_source, org_code, city_code, detail_address,
  39. lat, lng, approval, approval_time, manager, remark, status, create_by, create_time,
  40. update_by, update_time, del_flag,city_name
  41. </sql>
  42. <select id="selectByKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
  43. select
  44. <include refid="Base_Column_List" />
  45. from kws_enterprise
  46. where id = #{id,jdbcType=BIGINT}
  47. </select>
  48. <select id="findPojo" resultType="com.sckw.system.model.pojo.FindEntListPojo" parameterType="com.sckw.system.model.pojo.FindPojoParam">
  49. select tab.*,
  50. case when tab.id in (select ent_id from kws_ent_dep) then '子单位' else '主单位' end entDept,
  51. case when tab.status = 0 then '正常' else '冻结' end statusName from
  52. (
  53. select a.id,
  54. min(a.firm_name) firm_name,
  55. min(a.code) code,
  56. min(a.contacts) contacts,
  57. min(a.phone) phone,
  58. min(a.legal_name) legal_name,
  59. min(a.legal_phone) legal_phone,
  60. min(a.head) head,
  61. min(a.integral) integral,
  62. min(a.balance) balance,
  63. min(a.experience) experience,
  64. min(a.member_level) member_level,
  65. min(a.reg_time) reg_time,
  66. min(a.reg_source) reg_source,
  67. min(a.org_code) org_code,
  68. min(a.city_code) city_code,
  69. min(a.detail_address) detail_address,
  70. min(a.lat) lat,
  71. min(a.lng) lng,
  72. min(a.approval) approval,
  73. min(a.approval_time) approval_time,
  74. min(a.manager) manager,
  75. min(a.remark) remark,
  76. min(a.status) status,
  77. min(a.create_by) create_by,
  78. min(a.create_time) create_time,
  79. min(a.update_by) update_by,
  80. min(a.update_time) update_time,
  81. min(a.del_flag) del_flag,
  82. ifnull(GROUP_CONCAT(distinct b.type), '') type,
  83. min(k.system_type) system_type,
  84. min(k.name) createByName
  85. from kws_enterprise a
  86. left join kws_user k on a.create_by = k.id
  87. left join kws_ent_type b
  88. on a.id = b.ent_id
  89. <if test="dto.typeList != null and dto.typeList.size() > 0">and b.type in
  90. <foreach collection="dto.typeList" item="item" open="(" close=")" separator=",">
  91. #{item}
  92. </foreach>
  93. </if>
  94. where a.del_flag = 0
  95. and b.del_flag = 0
  96. <if test="dto.approval != null">
  97. and a.approval = #{dto.approval}
  98. </if>
  99. <if test="dto.keywords != null">
  100. and (a.contacts like concat('%', #{dto.keywords}, '%') or a.phone like concat('%', #{dto.keywords}, '%') or a.firm_name like concat('%', #{dto.keywords}, '%'))
  101. </if>
  102. <if test="dto.startTime != null">
  103. and a.update_time >= #{dto.startTime}
  104. </if>
  105. <if test="dto.endTime != null">
  106. and a.update_time &lt;= #{dto.endTime}
  107. </if>
  108. <if test="dto.approvalStartTime != null">
  109. and a.approval_time >= #{dto.approvalStartTime}
  110. </if>
  111. <if test="dto.approvalEndTime != null">
  112. and a.approval_time &lt;= #{dto.approvalEndTime}
  113. </if>
  114. <if test="dto.status != null and dto.status != ''">
  115. and a.status = #{dto.status}
  116. </if>
  117. <if test="dto.entryType != null and dto.entryType == '1'">
  118. and k.system_type = 2
  119. </if>
  120. <if test="dto.entryType != null and dto.entryType == '2'">
  121. and k.system_type = 1
  122. </if>
  123. <choose>
  124. <when test="dto.entDept != null and dto.entDept == 0">
  125. and not exists (select 1 from kws_ent_dep dep where a.id = dep.ent_id)
  126. </when>
  127. <when test="dto.entDept != null and dto.entDept == 1">
  128. and exists (select 1 from kws_ent_dep dep where a.id = dep.ent_id)
  129. </when>
  130. </choose>
  131. group by a.id
  132. ) tab
  133. where tab.id is not null
  134. order by tab.create_time desc
  135. </select>
  136. <select id="findList" resultType="com.sckw.system.model.KwsEnterprise" parameterType="com.sckw.system.model.vo.req.EntFindPageReqVo">
  137. select a.*
  138. from kws_enterprise a
  139. where a.del_flag = 0
  140. <if test="firmName != null and firmName != ''">
  141. and a.firm_name = #{firmName}
  142. </if>
  143. <if test="contacts != null and contacts != ''">
  144. and a.contacts = #{contacts}
  145. </if>
  146. <if test="phone != null and phone != ''">
  147. and a.phone = #{phone}
  148. </if>
  149. <if test="legalName != null and legalName != ''">
  150. and a.legal_name = #{legalName}
  151. </if>
  152. <if test="legalPhone != null and legalPhone != ''">
  153. and a.legal_phone = #{legalPhone}
  154. </if>
  155. <if test="approval != null">
  156. and a.approval = #{approval}
  157. </if>
  158. order by a.create_time
  159. </select>
  160. <select id="findByUserId" resultType="com.sckw.system.model.KwsEnterprise">
  161. select distinct a.*
  162. from kws_enterprise a
  163. inner join kws_dept b on a.id = b.ent_id
  164. inner join kws_user_dept c on b.id = c.dept_id
  165. inner join kws_user d on c.user_id = d.id
  166. where d.id = #{id}
  167. and a.del_flag = 0
  168. and b.del_flag = 0
  169. and c.del_flag = 0
  170. and d.del_flag = 0
  171. and a.status = 0
  172. and b.status = 0
  173. and c.status = 0
  174. and d.status = 0
  175. </select>
  176. <select id="selectByKeys" resultType="com.sckw.system.model.KwsEnterprise">
  177. select
  178. <include refid="Base_Column_List" />
  179. from kws_enterprise
  180. where id in
  181. <foreach collection="list" item="item" open="(" close=")" separator=",">
  182. #{item}
  183. </foreach>
  184. and del_flag = 0
  185. </select>
  186. <select id="findUserByEntIds" resultType="com.sckw.system.model.pojo.FindEntUserPojo">
  187. select distinct a.id entId,
  188. a.firm_name entName,
  189. d.id userId,
  190. d.name,
  191. d.account,
  192. d.phone
  193. from kws_enterprise a
  194. left join kws_dept b on a.id = b.ent_id
  195. left join kws_user_dept c on b.id = c.dept_id
  196. left join kws_user d on c.user_id = d.id
  197. where a.del_flag = 0
  198. and b.del_flag = 0
  199. and c.del_flag = 0
  200. and d.del_flag = 0
  201. and a.id in
  202. <foreach collection="list" separator="," open="(" close=")" item="item">
  203. #{item}
  204. </foreach>
  205. </select>
  206. <select id="findManageInfoByEntId" resultType="com.sckw.system.model.pojo.FindManagePojo">
  207. select distinct d.id userId,
  208. b.id deptId,
  209. f.id roleId
  210. from kws_enterprise a
  211. left join kws_dept b on a.id = b.ent_id
  212. left join kws_user_dept c on b.id = c.dept_id
  213. left join kws_user d on c.user_id = d.id
  214. left join kws_user_role e on d.id = e.user_id
  215. left join kws_role f on e.role_id = f.id
  216. where a.del_flag = 0
  217. and b.del_flag = 0
  218. and c.del_flag = 0
  219. and d.del_flag = 0
  220. and e.del_flag = 0
  221. and f.del_flag = 0
  222. and d.is_main = 1
  223. and d.system_type = 2
  224. and a.id = #{entId}
  225. </select>
  226. <select id="findManageInfoByEntIdBeforeApproval" resultType="com.sckw.system.model.pojo.FindManagePojo">
  227. select distinct d.id userId,
  228. f.id roleId
  229. from kws_enterprise a
  230. left join kws_dept b on a.id = b.ent_id
  231. LEFT JOIN kws_user d ON a.phone = d.account
  232. left join kws_role f on a.id = f.dept_id
  233. where a.del_flag = 0
  234. and b.del_flag = 0
  235. and d.del_flag = 0
  236. and f.del_flag = 0
  237. and d.is_main = 1
  238. and d.system_type = 2
  239. and a.id = #{entId}
  240. </select>
  241. <select id="queryEntByName" resultType="com.sckw.system.model.KwsEnterprise">
  242. select * from kws_enterprise where firm_name like concat('%', #{entName}, '%') and del_flag = 0
  243. </select>
  244. <insert id="insert" parameterType="com.sckw.system.model.KwsEnterprise">
  245. insert into kws_enterprise
  246. <trim prefix="(" suffix=")" suffixOverrides=",">
  247. <if test="id != null">
  248. id,
  249. </if>
  250. <if test="firmName != null">
  251. firm_name,
  252. </if>
  253. <if test="code != null">
  254. code,
  255. </if>
  256. <if test="contacts != null">
  257. contacts,
  258. </if>
  259. <if test="phone != null">
  260. phone,
  261. </if>
  262. <if test="legalName != null">
  263. legal_name,
  264. </if>
  265. <if test="legalPhone != null">
  266. legal_phone,
  267. </if>
  268. <if test="head != null">
  269. head,
  270. </if>
  271. <if test="integral != null">
  272. integral,
  273. </if>
  274. <if test="balance != null">
  275. balance,
  276. </if>
  277. <if test="experience != null">
  278. experience,
  279. </if>
  280. <if test="memberLevel != null">
  281. member_level,
  282. </if>
  283. <if test="regTime != null">
  284. reg_time,
  285. </if>
  286. <if test="regSource != null">
  287. reg_source,
  288. </if>
  289. <if test="orgCode != null">
  290. org_code,
  291. </if>
  292. <if test="cityCode != null">
  293. city_code,
  294. </if>
  295. <if test="detailAddress != null">
  296. detail_address,
  297. </if>
  298. <if test="lat != null">
  299. lat,
  300. </if>
  301. <if test="lng != null">
  302. lng,
  303. </if>
  304. <if test="approval != null">
  305. approval,
  306. </if>
  307. <if test="approvalTime != null">
  308. approval_time,
  309. </if>
  310. <if test="manager != null">
  311. manager,
  312. </if>
  313. <if test="remark != null">
  314. remark,
  315. </if>
  316. <if test="status != null">
  317. status,
  318. </if>
  319. <if test="createBy != null">
  320. create_by,
  321. </if>
  322. <if test="createTime != null">
  323. create_time,
  324. </if>
  325. <if test="updateBy != null">
  326. update_by,
  327. </if>
  328. <if test="updateTime != null">
  329. update_time,
  330. </if>
  331. <if test="delFlag != null">
  332. del_flag,
  333. </if>
  334. </trim>
  335. <trim prefix="values (" suffix=")" suffixOverrides=",">
  336. <if test="id != null">
  337. #{id,jdbcType=BIGINT},
  338. </if>
  339. <if test="firmName != null">
  340. #{firmName,jdbcType=VARCHAR},
  341. </if>
  342. <if test="code != null">
  343. #{code,jdbcType=VARCHAR},
  344. </if>
  345. <if test="contacts != null">
  346. #{contacts,jdbcType=VARCHAR},
  347. </if>
  348. <if test="phone != null">
  349. #{phone,jdbcType=VARCHAR},
  350. </if>
  351. <if test="legalName != null">
  352. #{legalName,jdbcType=VARCHAR},
  353. </if>
  354. <if test="legalPhone != null">
  355. #{legalPhone,jdbcType=VARCHAR},
  356. </if>
  357. <if test="head != null">
  358. #{head,jdbcType=VARCHAR},
  359. </if>
  360. <if test="integral != null">
  361. #{integral,jdbcType=INTEGER},
  362. </if>
  363. <if test="balance != null">
  364. #{balance,jdbcType=DECIMAL},
  365. </if>
  366. <if test="experience != null">
  367. #{experience,jdbcType=INTEGER},
  368. </if>
  369. <if test="memberLevel != null">
  370. #{memberLevel,jdbcType=INTEGER},
  371. </if>
  372. <if test="regTime != null">
  373. #{regTime,jdbcType=TIMESTAMP},
  374. </if>
  375. <if test="regSource != null">
  376. #{regSource,jdbcType=VARCHAR},
  377. </if>
  378. <if test="orgCode != null">
  379. #{orgCode,jdbcType=VARCHAR},
  380. </if>
  381. <if test="cityCode != null">
  382. #{cityCode,jdbcType=INTEGER},
  383. </if>
  384. <if test="detailAddress != null">
  385. #{detailAddress,jdbcType=VARCHAR},
  386. </if>
  387. <if test="lat != null">
  388. #{lat,jdbcType=VARCHAR},
  389. </if>
  390. <if test="lng != null">
  391. #{lng,jdbcType=VARCHAR},
  392. </if>
  393. <if test="approval != null">
  394. #{approval,jdbcType=INTEGER},
  395. </if>
  396. <if test="approvalTime != null">
  397. #{approvalTime,jdbcType=TIMESTAMP},
  398. </if>
  399. <if test="manager != null">
  400. #{manager,jdbcType=BIGINT},
  401. </if>
  402. <if test="remark != null">
  403. #{remark,jdbcType=VARCHAR},
  404. </if>
  405. <if test="status != null">
  406. #{status,jdbcType=INTEGER},
  407. </if>
  408. <if test="createBy != null">
  409. #{createBy,jdbcType=BIGINT},
  410. </if>
  411. <if test="createTime != null">
  412. #{createTime,jdbcType=TIMESTAMP},
  413. </if>
  414. <if test="updateBy != null">
  415. #{updateBy,jdbcType=BIGINT},
  416. </if>
  417. <if test="updateTime != null">
  418. #{updateTime,jdbcType=TIMESTAMP},
  419. </if>
  420. <if test="delFlag != null">
  421. #{delFlag,jdbcType=INTEGER},
  422. </if>
  423. </trim>
  424. </insert>
  425. <update id="update" parameterType="com.sckw.system.model.KwsEnterprise">
  426. update kws_enterprise
  427. <set>
  428. <if test="firmName != null">
  429. firm_name = #{firmName,jdbcType=VARCHAR},
  430. </if>
  431. <if test="code != null">
  432. code = #{code,jdbcType=VARCHAR},
  433. </if>
  434. <if test="contacts != null">
  435. contacts = #{contacts,jdbcType=VARCHAR},
  436. </if>
  437. <if test="phone != null">
  438. phone = #{phone,jdbcType=VARCHAR},
  439. </if>
  440. <if test="legalName != null">
  441. legal_name = #{legalName,jdbcType=VARCHAR},
  442. </if>
  443. <if test="legalPhone != null">
  444. legal_phone = #{legalPhone,jdbcType=VARCHAR},
  445. </if>
  446. <if test="head != null">
  447. head = #{head,jdbcType=VARCHAR},
  448. </if>
  449. <if test="integral != null">
  450. integral = #{integral,jdbcType=INTEGER},
  451. </if>
  452. <if test="balance != null">
  453. balance = #{balance,jdbcType=DECIMAL},
  454. </if>
  455. <if test="experience != null">
  456. experience = #{experience,jdbcType=INTEGER},
  457. </if>
  458. <if test="memberLevel != null">
  459. member_level = #{memberLevel,jdbcType=INTEGER},
  460. </if>
  461. <if test="regTime != null">
  462. reg_time = #{regTime,jdbcType=TIMESTAMP},
  463. </if>
  464. <if test="regSource != null">
  465. reg_source = #{regSource,jdbcType=VARCHAR},
  466. </if>
  467. <if test="orgCode != null">
  468. org_code = #{orgCode,jdbcType=VARCHAR},
  469. </if>
  470. <if test="cityCode != null">
  471. city_code = #{cityCode,jdbcType=INTEGER},
  472. </if>
  473. <if test="cityName != null">
  474. city_name = #{cityName,jdbcType=VARCHAR},
  475. </if>
  476. <if test="detailAddress != null">
  477. detail_address = #{detailAddress,jdbcType=VARCHAR},
  478. </if>
  479. <if test="lat != null">
  480. lat = #{lat,jdbcType=VARCHAR},
  481. </if>
  482. <if test="lng != null">
  483. lng = #{lng,jdbcType=VARCHAR},
  484. </if>
  485. <if test="approval != null">
  486. approval = #{approval,jdbcType=INTEGER},
  487. </if>
  488. <if test="approvalTime != null">
  489. approval_time = #{approvalTime,jdbcType=TIMESTAMP},
  490. </if>
  491. <if test="manager != null">
  492. manager = #{manager,jdbcType=BIGINT},
  493. </if>
  494. <if test="remark != null">
  495. remark = #{remark,jdbcType=VARCHAR},
  496. </if>
  497. <if test="status != null">
  498. status = #{status,jdbcType=INTEGER},
  499. </if>
  500. <if test="createBy != null">
  501. create_by = #{createBy,jdbcType=BIGINT},
  502. </if>
  503. <if test="createTime != null">
  504. create_time = #{createTime,jdbcType=TIMESTAMP},
  505. </if>
  506. <if test="updateBy != null">
  507. update_by = #{updateBy,jdbcType=BIGINT},
  508. </if>
  509. <if test="updateTime != null">
  510. update_time = #{updateTime,jdbcType=TIMESTAMP},
  511. </if>
  512. <if test="delFlag != null">
  513. del_flag = #{delFlag,jdbcType=INTEGER},
  514. </if>
  515. </set>
  516. where id = #{id,jdbcType=BIGINT}
  517. </update>
  518. <update id="approval">
  519. update kws_enterprise
  520. set approval = #{approval},
  521. approval_time = now(),
  522. remark = #{remark}
  523. where id = #{id,jdbcType=BIGINT}
  524. and approval in (3, 4)
  525. and del_flag = 0
  526. </update>
  527. </mapper>