KwsEnterpriseDao.xml 18 KB

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