KwsEnterpriseDao.xml 18 KB

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