KwsEnterpriseDao.xml 20 KB

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