TakaiApplicationMapper.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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="com.takai.ai.mapper.TakaiApplicationMapper">
  6. <resultMap type="com.takai.ai.domain.entity.TakaiApplication" id="BmApplicationResult">
  7. <id property="appId" column="appId" />
  8. <result property="name" column="name" />
  9. <result property="desc" column="description" />
  10. <result property="prompt" column="prompt" />
  11. <result property="topP" column="top_p" />
  12. <result property="temperature" column="temperature" />
  13. <result property="knowledgeIds" column="knowledge_ids" />
  14. <result property="sliceCount" column="slice_count" />
  15. <result property="model" column="model" />
  16. <result property="isDeepThink" column="is_deep_think" />
  17. <result property="iconColor" column="icon_color" />
  18. <result property="iconType" column="icon_type" />
  19. <result property="maxToken" column="max_token" />
  20. <result property="paramDesc" column="param_desc"/>
  21. <result property="knowledgeInfo" column="knowledge_info" />
  22. <result property="typeId" column="type_id" />
  23. <result property="visible" column="visible" />
  24. <result property="sort" column="sort" />
  25. <result property="status" column="status" />
  26. <result property="approver" column="approver" />
  27. <result property="nodeOrder" column="node_order" />
  28. <result property="comment" column="comment" />
  29. <result property="remark" column="remark" />
  30. <result property="createBy" column="create_by" />
  31. <result property="createTime" column="create_time" />
  32. <result property="updateBy" column="update_by" />
  33. <result property="updateTime" column="update_time" />
  34. </resultMap>
  35. <resultMap type="com.takai.ai.domain.entity.TakaiApplicationResult" id="BmApplicationListResult">
  36. <id property="appId" column="appId" />
  37. <result property="name" column="name" />
  38. <result property="desc" column="description" />
  39. <result property="prompt" column="prompt" />
  40. <result property="typeId" column="type_id" />
  41. <result property="visible" column="visible" />
  42. <result property="sort" column="sort" />
  43. <result property="status" column="status" />
  44. <result property="approver" column="approver" />
  45. <result property="comment" column="comment" />
  46. <result property="userName" column="user_name" />
  47. <result property="createBy" column="create_by" />
  48. <result property="createTime" column="create_time" />
  49. <result property="typeName" column="typeName" />
  50. <result property="chatMode" column="chatMode" />
  51. <result property="isIsCollect" column="isIsCollect" />
  52. <result property="auditStatus" column="auditStatus" />
  53. <result property="projectName" column="projectName" />
  54. <result property="updateTime" column="update_time" />
  55. </resultMap>
  56. <sql id="selectSql">
  57. select appId, name, description, prompt, top_p, temperature, knowledge_ids, slice_count,model,icon_color,icon_type,max_token, param_desc, knowledge_info, type_id,
  58. status, approver, node_order, comment,remark, create_by, create_time, update_by, update_time, is_deep_think,visible,sort
  59. from bm_application
  60. </sql>
  61. <select id="selectApplicationList" parameterType="com.takai.ai.domain.entity.TakaiApplication" resultMap="BmApplicationListResult">
  62. <!-- 管理员管理所有应用 -->
  63. <if test="params != null and params.isAdmin">
  64. SELECT DISTINCT
  65. bm.appId,
  66. bm.name,
  67. bm.description,
  68. bm.type_id,
  69. bm.create_by,
  70. bm.create_time,
  71. bm.status,
  72. bm.comment,
  73. (SELECT dai.STATUS
  74. FROM document_audit_info dai
  75. WHERE dai.app_id = bm.appId
  76. ORDER BY dai.create_time DESC
  77. LIMIT 1) AS auditStatus,
  78. sp.project_name as projectName,
  79. bm.update_time,
  80. bm.sort
  81. FROM
  82. bm_application bm
  83. LEFT JOIN sys_project_app pa ON pa.app_id = bm.appId
  84. LEFT JOIN sys_project sp ON pa.project_id = sp.project_id
  85. <where>
  86. <if test="flag != null and flag != ''">
  87. AND (
  88. <choose>
  89. <when test="flag == 1">
  90. bm.status = '1' OR bm.status = '2' or bm.status = '3' OR bm.status = '4' OR bm.status = '5' OR bm.status = '' OR bm.status IS NULL
  91. </when>
  92. <otherwise>
  93. bm.status = '3' OR bm.status = '' OR bm.status IS NULL
  94. </otherwise>
  95. </choose>
  96. )
  97. </if>
  98. <if test="typeId != null and typeId != ''">
  99. AND bm.type_id = #{typeId}
  100. </if>
  101. <if test="projectId != null and projectId != ''">
  102. AND sp.project_id = #{projectId}
  103. </if>
  104. </where>
  105. ORDER BY sort IS NULL, sort ASC, bm.update_time DESC, bm.create_time DESC
  106. </if>
  107. <if test="params == null or !params.isAdmin">
  108. SELECT DISTINCT
  109. bm.appId,
  110. bm.name,
  111. bm.description,
  112. bm.type_id,
  113. bm.create_by,
  114. bm.create_time,
  115. bm.status,
  116. bm.comment,
  117. bm.visible,
  118. (SELECT dai.STATUS
  119. FROM document_audit_info dai
  120. WHERE dai.app_id = bm.appId
  121. ORDER BY dai.create_time DESC
  122. LIMIT 1) AS auditStatus,
  123. sp.project_name as projectName,
  124. bm.update_time,
  125. bm.sort
  126. FROM
  127. bm_application bm
  128. LEFT JOIN sys_project_app pa ON pa.app_id = bm.appId
  129. LEFT JOIN sys_project sp ON pa.project_id = sp.project_id
  130. LEFT JOIN sys_project_staff spa ON spa.project_pid = sp.project_pid
  131. LEFT JOIN sys_dict_data sdd ON sdd.dict_code = bm.type_id
  132. where
  133. (bm.visible is null or bm.visible='0')
  134. <if test="flag != null and flag != ''">
  135. AND (
  136. <choose>
  137. <when test="flag == 1">
  138. bm.status = '1' OR bm.status = '2' or bm.status = '3' OR bm.status = '4' OR bm.status = '5' OR bm.status = '' OR bm.status IS NULL
  139. </when>
  140. <otherwise>
  141. bm.status = '3' OR bm.status = '' OR bm.status IS NULL
  142. </otherwise>
  143. </choose>
  144. )
  145. </if>
  146. <if test="approver != null and approver != ''">
  147. AND spa.user_id = #{approver}
  148. </if>
  149. <if test="typeId != null and typeId != ''">
  150. AND bm.type_id = #{typeId}
  151. </if>
  152. <if test="projectId != null and projectId != ''">
  153. AND sp.project_id = #{projectId}
  154. </if>
  155. <if test="projectId == null or projectId == ''">
  156. <!-- 用户所属项目下以外的应用 -->
  157. UNION
  158. SELECT
  159. ba.appId,
  160. ba.name,
  161. ba.description,
  162. ba.type_id,
  163. ba.create_by,
  164. ba.create_time,
  165. ba.status,
  166. ba.comment,
  167. ba.visible,
  168. (SELECT dai.STATUS
  169. FROM document_audit_info dai
  170. WHERE dai.app_id = ba.appId
  171. ORDER BY dai.create_time DESC
  172. LIMIT 1) AS auditStatus,
  173. '' AS projectName,
  174. ba.update_time,
  175. ba.sort
  176. FROM
  177. bm_application ba
  178. LEFT JOIN sys_dict_data sdd on sdd.dict_code = ba.type_id
  179. WHERE
  180. (ba.visible is null or ba.visible='0')
  181. AND ba.appId NOT IN (
  182. SELECT
  183. app_id
  184. FROM
  185. sys_project_app
  186. )
  187. AND (
  188. ba.STATUS = '3'
  189. OR ba.STATUS = ''
  190. OR ba.STATUS IS NULL
  191. )
  192. <if test="typeId != null and typeId != ''">
  193. AND ba.type_id = #{typeId}
  194. </if>
  195. <!-- 待审核的应用 -->
  196. UNION
  197. SELECT DISTINCT
  198. bl.appId,
  199. bl.name,
  200. bl.description,
  201. bl.type_id,
  202. bl.create_by,
  203. bl.create_time,
  204. bl.status,
  205. bl.comment,
  206. bl.visible,
  207. (SELECT dai.STATUS
  208. FROM document_audit_info dai
  209. WHERE dai.app_id = bl.appId
  210. ORDER BY dai.create_time DESC
  211. LIMIT 1) AS auditStatus,
  212. '' AS projectName,
  213. bl.update_time,
  214. bl.sort
  215. FROM
  216. bm_application bl
  217. WHERE
  218. (bl.visible is null or bl.visible='0')
  219. <if test="flag != null and flag != ''">
  220. AND (
  221. <choose>
  222. <when test="flag == 1">
  223. (bl.status = '1' OR bl.status = '2' OR bl.status = '3' OR bl.status = '4' OR bl.status = '5') AND (bl.create_by = #{approver} OR bl.update_by = #{approver})
  224. </when>
  225. <otherwise>
  226. bl.status = '3' OR bl.status = '' OR bl.status IS NULL
  227. </otherwise>
  228. </choose>
  229. )
  230. </if>
  231. AND bl.appId NOT IN (
  232. SELECT
  233. app_id
  234. FROM
  235. sys_project_app
  236. )
  237. <if test="typeId != null and typeId != ''">
  238. AND bl.type_id = #{typeId}
  239. </if>
  240. </if>
  241. <!-- 私有应用 -->
  242. UNION
  243. SELECT
  244. ba.appId,
  245. ba.name,
  246. ba.description,
  247. ba.type_id,
  248. ba.create_by,
  249. ba.create_time,
  250. ba.status,
  251. ba.comment,
  252. ba.visible,
  253. (SELECT dai.STATUS
  254. FROM document_audit_info dai
  255. WHERE dai.app_id = ba.appId
  256. ORDER BY dai.create_time DESC
  257. LIMIT 1) AS auditStatus,
  258. '' AS projectName,
  259. ba.update_time,
  260. ba.sort
  261. FROM
  262. bm_application ba
  263. LEFT JOIN sys_dict_data sdd on sdd.dict_code = ba.type_id
  264. WHERE
  265. ba.visible='1'
  266. and ba.create_by= #{params.userId}
  267. <if test="typeId != null and typeId != ''">
  268. AND ba.type_id = #{typeId}
  269. </if>
  270. <if test="addOrderBy == null or addOrderBy == 'Y'">
  271. ORDER BY sort IS NULL, sort ASC, update_time DESC, create_time DESC
  272. </if>
  273. </if>
  274. </select>
  275. <select id="selectTargetApplication" parameterType="BmApplication" resultMap="BmApplicationResult">
  276. <include refid="selectSql"/>
  277. where appId = #{appId}
  278. </select>
  279. <insert id="insertApplication" parameterType="TakaiApplication">
  280. insert into bm_application(
  281. <if test="appId != null">appId,</if>
  282. <if test="name != null and name != ''">name,</if>
  283. <if test="desc != null and desc != ''">description,</if>
  284. <if test="prompt != null and prompt != ''">prompt,</if>
  285. <if test="topP != null and topP != ''">top_p,</if>
  286. <if test="temperature != null and temperature != ''">temperature,</if>
  287. <if test="knowledgeIds != null and knowledgeIds != ''">knowledge_ids,</if>
  288. <if test="sliceCount != null">slice_count,</if>
  289. <if test="model != null and model != ''">model,</if>
  290. <if test="iconColor != null and iconColor != ''">icon_color,</if>
  291. <if test="iconType != null and iconType != ''">icon_type,</if>
  292. <if test="remark != null and remark != ''">remark,</if>
  293. <if test="createBy != null and createBy != ''">create_by,</if>
  294. <if test="knowledgeInfo != null and knowledgeInfo != ''">knowledge_info,</if>
  295. <if test="maxToken != null and maxToken != ''">max_token,</if>
  296. <if test="typeId != null and typeId != ''">type_id,</if>
  297. <if test="status != null and status != ''">status,</if>
  298. <if test="nodeOrder != null and nodeOrder != ''">node_order,</if>
  299. <if test="approver != null and approver != ''">approver,</if>
  300. <if test="comment != null and comment != ''">comment,</if>
  301. <if test="isDeepThink != null and isDeepThink != ''">is_deep_think,</if>
  302. <if test="visible != null and visible != ''">visible,</if>
  303. <if test="sort != null">sort,</if>
  304. create_time,
  305. update_time
  306. )values(
  307. <if test="appId != null">#{appId},</if>
  308. <if test="name != null and name != ''">#{name},</if>
  309. <if test="desc != null and desc != ''">#{desc},</if>
  310. <if test="prompt != null and prompt != ''">#{prompt},</if>
  311. <if test="topP != null and topP != ''">#{topP},</if>
  312. <if test="temperature != null and temperature != ''">#{temperature},</if>
  313. <if test="knowledgeIds != null and knowledgeIds != ''">#{knowledgeIds},</if>
  314. <if test="sliceCount != null">#{sliceCount},</if>
  315. <if test="model != null and model != ''">#{model},</if>
  316. <if test="iconColor != null and iconColor != ''">#{iconColor},</if>
  317. <if test="iconType != null and iconType != ''">#{iconType},</if>
  318. <if test="remark != null and remark != ''">#{remark},</if>
  319. <if test="createBy != null and createBy != ''">#{createBy},</if>
  320. <if test="knowledgeInfo != null and knowledgeInfo != ''">#{knowledgeInfo},</if>
  321. <if test="maxToken != null and maxToken != ''">#{maxToken},</if>
  322. <if test="typeId != null and typeId != ''">#{typeId},</if>
  323. <if test="status != null and status != ''">#{status},</if>
  324. <if test="nodeOrder != null and nodeOrder != ''">#{nodeOrder},</if>
  325. <if test="approver != null and approver != ''">#{approver},</if>
  326. <if test="comment != null and comment != ''">#{comment},</if>
  327. <if test="isDeepThink != null and isDeepThink != ''">#{isDeepThink},</if>
  328. <if test="visible != null and visible != ''">#{visible},</if>
  329. <if test="sort != null">#{sort},</if>
  330. sysdate(),
  331. sysdate()
  332. )
  333. </insert>
  334. <update id="updateApplication" parameterType="BmApplication">
  335. update bm_application
  336. <set>
  337. <if test="name != null and name != ''">name = #{name},</if>
  338. <if test="desc != null and desc != ''">description = #{desc},</if>
  339. <if test="prompt != null and prompt != ''">prompt = #{prompt},</if>
  340. <if test="topP != null and topP != ''">top_p = #{topP},</if>
  341. <if test="temperature != null and temperature != ''">temperature = #{temperature},</if>
  342. <if test="knowledgeIds != null and knowledgeIds != ''">knowledge_ids = #{knowledgeIds},</if>
  343. <if test="sliceCount != null">slice_count = #{sliceCount},</if>
  344. <if test="model != null and model != ''">model = #{model},</if>
  345. <if test="iconColor != null and iconColor != ''">icon_color = #{iconColor},</if>
  346. <if test="iconType != null and iconType != ''">icon_type = #{iconType},</if>
  347. <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  348. <if test="remark != null">remark = #{remark},</if>
  349. <if test="knowledgeInfo != null and knowledgeInfo != ''">knowledge_info = #{knowledgeInfo},</if>
  350. <if test="maxToken != null and maxToken != ''">max_token = #{maxToken},</if>
  351. <if test="isDeepThink != null and isDeepThink != ''">is_deep_think = #{isDeepThink},</if>
  352. <if test="visible != null and visible != ''">visible = #{visible},</if>
  353. <if test="sort != null">sort = #{sort},</if>
  354. type_id = #{typeId},
  355. <if test="status != null and status != ''">status = #{status},</if>
  356. node_order = #{nodeOrder},
  357. comment = #{comment},
  358. <if test="approver != null and approver != ''">approver = #{approver},</if>
  359. update_time = sysdate()
  360. </set>
  361. where appId = #{appId}
  362. </update>
  363. <delete id="delApplication" parameterType="String">
  364. delete from bm_application where appId = #{appId}
  365. </delete>
  366. <select id="selectAppListByApprover" parameterType="BmApplication" resultMap="BmApplicationListResult">
  367. select bm.appId, bm.name, bm.description, bm.prompt, bm.type_id,
  368. bm.status, bm.approver, bm.comment, bm.create_time, su.user_name, bm.is_deep_think, bm.visible
  369. from bm_application bm
  370. left join sys_user su on bm.approver = su.user_id
  371. <where>
  372. (bm.status = '4' OR bm.status = '1' OR bm.status = '2')
  373. <if test="appId != null and appId != ''">
  374. AND bm.appId = #{appId}
  375. </if>
  376. <if test="approver != null and approver != ''">
  377. AND bm.approver = #{approver}
  378. </if>
  379. </where>
  380. order by bm.create_time desc
  381. </select>
  382. <select id="selectAppByUserId" resultMap="BmApplicationListResult">
  383. SELECT DISTINCT
  384. bm.appId,
  385. bm. NAME,
  386. bm.description,
  387. bm.type_id,
  388. bm.visible,
  389. bm.create_time,
  390. sdd.dict_label AS typeName,
  391. 'LOCAL' AS chatMode,
  392. CASE
  393. WHEN ac.app_id IS NOT NULL THEN
  394. true
  395. ELSE
  396. false
  397. END AS isIsCollect
  398. FROM
  399. sys_project sp
  400. LEFT JOIN sys_project_staff spa ON sp.project_pid = spa.project_pid
  401. LEFT JOIN sys_project_app pa ON pa.project_id = sp.project_id
  402. LEFT JOIN bm_application bm ON pa.app_id = bm.appId
  403. LEFT JOIN sys_dict_data sdd ON sdd.dict_code = bm.type_id
  404. LEFT JOIN app_collect ac ON ac.app_id = bm.appId
  405. AND ac.user_id = #{userId}
  406. where
  407. spa.user_id = #{userId}
  408. AND (
  409. bm. STATUS = '3'
  410. OR bm. STATUS = ''
  411. OR bm. STATUS IS NULL
  412. )
  413. </select>
  414. <select id="selectApplicationListByProjectType" parameterType="String" resultMap="BmApplicationListResult">
  415. select
  416. distinct bm.appId,
  417. bm.name,
  418. bm.description,
  419. bm.create_time,
  420. bm.status,
  421. bm.comment,
  422. bm.type_id,
  423. bm.visible
  424. from
  425. bm_application bm
  426. LEFT JOIN sys_project_app pa ON bm.appId = pa.app_id
  427. LEFT JOIN sys_project sp on pa.project_id = sp.project_id
  428. where bm.appId = #{appId}
  429. and (bm.type_id = 42 or bm.type_id = 43)
  430. </select>
  431. <select id="selectRoleApp" resultMap="BmApplicationListResult">
  432. SELECT DISTINCT
  433. bm.appId,
  434. bm. NAME,
  435. bm.description,
  436. bm.type_id,
  437. bm.visible,
  438. bm.create_time
  439. FROM
  440. bm_application bm
  441. where
  442. bm. STATUS = '3'
  443. OR bm. STATUS = ''
  444. OR bm. STATUS IS NULL
  445. </select>
  446. <insert id="insertVipApp" parameterType="VipApplication">
  447. insert into vip_application
  448. <trim prefix="(" suffix=")" suffixOverrides=",">
  449. <if test="appId != null">appId,</if>
  450. <if test="userId != null">user_id,</if>
  451. </trim>
  452. <trim prefix="values (" suffix=")" suffixOverrides=",">
  453. <if test="appId != null">#{appId},</if>
  454. <if test="userId != null">#{userId},</if>
  455. </trim>
  456. </insert>
  457. <delete id="deleteVipByAppId" parameterType="String">
  458. delete from vip_application where appId = #{appId}
  459. </delete>
  460. </mapper>