CommonMapper.xml 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056
  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.dk.mdm.mapper.common.CommonMapper">
  4. <!-- 获取显示顺序的最大值 -->
  5. <select id="getMaxDisplayNo" resultType="Integer">
  6. select max(display_no) + 1
  7. from ${table}
  8. where 1=1
  9. <if test="flgValid != null">
  10. and flg_valid = #{flgValid}
  11. </if>
  12. <if test="ftyId != null">
  13. and fty_id = #{ftyId}
  14. </if>
  15. <if test="otherCond">
  16. and ${otherCond}
  17. </if>
  18. <!--数据字典-->
  19. <if test="dictCode != null">
  20. and dict_code = #{dictCode}
  21. </if>
  22. </select>
  23. <!--获取编码-->
  24. <select id="getUniqueCode" resultType="java.util.Map">
  25. select out_id AS "outId", out_code AS "outNote"
  26. from dkic_b.f_create_code_id(#{cpId}, #{docName});
  27. </select>
  28. <!--获取单号-->
  29. <select id="getUniqueNote" resultType="java.util.Map">
  30. select out_id AS "outId", out_note AS "outNote"
  31. from dkic_b.f_create_note_id(#{cpId}, #{docName});
  32. </select>
  33. <!-- 获取用户菜单-->
  34. <select id="getMenuByUser" resultType="java.util.Map">
  35. select menu_uuid AS "menuUuid",
  36. name AS "name",
  37. menu_name AS "menuName",
  38. parent_uuid AS "parentUuid",
  39. menu_type AS "menuType",
  40. flg_menu AS "flgMenu",
  41. object_code AS "objectCode",
  42. object_path AS "objectPath",
  43. object_icon AS "icon",
  44. object_id AS "objectId",
  45. menu_tags AS "menuTags",
  46. level_code AS "levelCode",
  47. flg_same_route AS "flgSameRoute",
  48. flg_choose_id AS "flgChooseId",
  49. flg_auto_query AS "flgAutoQuery",
  50. page_grid_info AS "pageGridInfo",
  51. grade_code AS "gradeCode",
  52. grade_level AS "gradeLevel",
  53. is_vip AS "isVip",
  54. fun_uuid AS "funUuid",
  55. #{appCode} AS "appCode",
  56. menu_uuid AS "id",
  57. parent_uuid AS "parentId"
  58. from
  59. dkic_b.f_get_user_menu(#{appCode}, #{userId } ::uuid,#{cpId},#{lang})
  60. </select>
  61. <!--查用户功能权限-->
  62. <select id="getUserFunction" resultType="java.util.Map">
  63. select appm.menu_uuid AS "menuUuid"
  64. , appm.menu_name as name
  65. , sys.f_get_name_i18n(appm.menu_name_i18n, #{i18n}) as "menuName"
  66. , rr.fun_uuid AS "funUuid"
  67. , appm.object_code AS "objectCode"
  68. , appm.menu_type AS "menuType"
  69. from sys.t_app_menu appm
  70. inner join core.t_user_fun rr
  71. on rr.fun_uuid = appm.fun_uuid
  72. where appm.flg_valid
  73. and appm.app_code = #{appCode}
  74. and appm.menu_type IN (1, 2)
  75. and rr.user_id = #{userId};
  76. </select>
  77. <!--查询用于隐藏列信息-->
  78. <select id="getUserTableInfo" resultType="java.util.Map">
  79. select tuts.code,
  80. tuts.table_type AS "tableType",
  81. tuts.table_ref AS "tableRef",
  82. tuts.columns
  83. from pset.t_user_table_set tuts
  84. where tuts.flg_valid
  85. and tuts.user_id = #{userId};
  86. </select>
  87. <!--查导航菜单(自定义报表用)-->
  88. <select id="getMenuNavigation" resultType="java.util.Map">
  89. select appm.menu_uuid AS "menuUuid"
  90. ,sys.f_get_name_i18n(appm.menu_name_i18n,#{i18n}) as "menuName"
  91. ,appm.parent_uuid AS "parentUuid"
  92. from sys.t_app_menu appm
  93. where appm.flg_valid
  94. <if test="parentUuid">
  95. and appm.parent_uuid = #{parentUuid} ::uuid
  96. </if>
  97. and appm.app_code = 'WEB-MAIN'
  98. and appm.menu_type = 0
  99. </select>
  100. <!-- 获取应用-->
  101. <select id="getApplication" resultType="java.util.Map">
  102. select
  103. app_code as "appCode",
  104. app_name as "appName"
  105. from sys.t_application
  106. </select>
  107. <!--获取单据-->
  108. <select id="getDoc" resultType="java.util.Map">
  109. SELECT
  110. tsd.doc_name AS "docName"
  111. FROM
  112. sys.t_doc tsd
  113. <where>
  114. <if test="flgApproval!=null">
  115. and tsd.flg_approval = #{flgApproval}
  116. </if>
  117. <if test="flgPrint!=null">
  118. and tsd.flg_print = #{flgPrint}
  119. </if>
  120. </where>
  121. </select>
  122. <!-- 获取数据种类 -->
  123. <select id="getDataKind" resultType="java.util.Map">
  124. select kind_code AS "kindCode",
  125. sys.f_get_name_i18n(kind_name_i18n,#{i18n}) as "kindName",
  126. sys.f_get_name_i18n(kind_desc,#{i18n}) as "gradeKindDesc",
  127. kind_type AS "kindType",
  128. kind_tags AS "kindTags",
  129. display_no AS "displayNo",
  130. kind_code AS "id",
  131. remarks
  132. from sys.t_data_kind
  133. where flg_valid
  134. <if test="kindType != null">
  135. AND kind_type = #{kindType}
  136. </if>
  137. <if test="usedFlag != null">
  138. AND kind_tags -> 'used' ?? '标签'
  139. </if>
  140. <if test="kindTag != null">
  141. AND kind_tags -> 'used' ?? #{kindTag}
  142. </if>
  143. <if test="kindCodeList != null and kindCodeList.size()>0">
  144. AND kind_code =any(#{kindCodeList,typeHandler=StringListTypeHandler})
  145. </if>
  146. order by display_no
  147. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  148. limit #{end} offset #{start}
  149. </if>
  150. </select>
  151. <!-- 获取组织部门 -->
  152. <select id="getOrg" resultType="java.util.Map">
  153. select org_Id AS "orgId",
  154. org_code AS "orgCode",
  155. org_name AS "orgName",
  156. org_Id AS "id",
  157. parent_id AS "parentId",
  158. top_Id AS "topId",
  159. display_no AS "displayNo",
  160. level_code AS "levelCode",
  161. level_no AS "levelNo",
  162. remarks
  163. ,flg_valid as "flgValid"
  164. ,flg_business as "flgBusiness"
  165. from dkic_b.t_mst_org
  166. where flg_valid
  167. and cp_id = #{cpId}
  168. <if test="topId != null">
  169. AND top_id = #{topId}
  170. </if>
  171. <if test="orgId != null">
  172. AND org_id != #{orgId}
  173. </if>
  174. <if test="orgCode != null">
  175. AND org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  176. </if>
  177. <if test="orgName != null">
  178. AND org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  179. </if>
  180. <if test="flgBusiness != null">
  181. AND flg_business = #{flgBusiness}
  182. </if>
  183. <if test="searchText !=null">
  184. AND ( org_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  185. or org_code LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  186. </if>
  187. <if test="ids != null and ids.size() > 0 ">
  188. order by case org_id
  189. <foreach collection="ids" index="index" item="item">
  190. when #{item}::uuid then #{item}::uuid
  191. </foreach>
  192. end
  193. </if>
  194. <if test="ids == null">
  195. order by display_no
  196. </if>
  197. </select>
  198. <!-- 只获取二级部门 按照level_code 排序 -->
  199. <select id="getProcureOrg" resultType="java.util.Map">
  200. select org_Id AS "orgId",
  201. org_code AS "orgCode",
  202. org_name AS "orgName",
  203. org_Id AS "id",
  204. parent_id AS "parentId",
  205. top_Id AS "topId",
  206. display_no AS "displayNo",
  207. remarks
  208. from dkic_b.t_mst_org
  209. where flg_valid
  210. and cp_id = #{cpId}
  211. and parent_id is NOT null
  212. <if test="topId != null">
  213. AND top_id = #{topId}
  214. </if>
  215. <if test="orgId != null">
  216. AND org_id != #{orgId}
  217. </if>
  218. <if test="orgCode != null">
  219. AND org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  220. </if>
  221. <if test="orgName != null">
  222. AND org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  223. </if>
  224. order by level_code
  225. </select>
  226. <!-- t_mst_org,(条件查询)个数 -->
  227. <select id="getOrgCountByPage" resultType="Long">
  228. SELECT
  229. count(1)
  230. from dkic_b.t_mst_org
  231. where flg_valid
  232. and cp_id = #{cpId}
  233. <if test="topId != null">
  234. AND top_id = #{topId}
  235. </if>
  236. <if test="orgId != null">
  237. AND org_id != #{orgId}
  238. </if>
  239. <if test="orgCode != null">
  240. AND org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  241. </if>
  242. <if test="orgName != null">
  243. AND org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  244. </if>
  245. </select>
  246. <!-- 获取角色 -->
  247. <select id="getRole" resultType="java.util.Map">
  248. select role_Id AS "roleId",
  249. role_code AS "roleCode",
  250. role_name AS "roleName",
  251. display_no AS "displayNo",
  252. remarks
  253. from dkic_b.t_mst_role
  254. where cp_id = #{cpId}
  255. and flg_valid
  256. <if test="searchText !=null">
  257. AND role_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  258. </if>
  259. order by display_no
  260. </select>
  261. <!-- 获取员工 -->
  262. <select id="getStaffByPage" resultType="java.util.Map">
  263. select staff.staff_id AS "staffId",
  264. staff.staff_code AS "staffCode",
  265. staff.staff_name AS "staffName",
  266. staff.staff_phone AS "staffPhone",
  267. sys.f_code_name(staff.staff_code, staff.staff_name) AS "staffCodeName",
  268. staff.remarks
  269. ,tmg.org_id as "orgId"
  270. ,tmg.org_code as "orgCode"
  271. ,tmg.org_name as "orgName"
  272. ,staff.flg_valid as "flgValid"
  273. from dkic_b.t_mst_staff AS staff
  274. left join dkic_b.t_mst_org tmg on tmg.org_id = staff.org_id
  275. where staff.flg_valid
  276. and staff.cp_id =#{cpId}
  277. and staff.flg_ghost = false
  278. <if test="staffCode != null and staffCode != ''">
  279. And position (#{staffCode} in staff.staff_code)>0
  280. </if>
  281. <if test="staffName != null and staffName != ''">
  282. And position (#{staffName} in staff.staff_name)>0
  283. </if>
  284. <if test="searchText !=null">
  285. AND ( staff.staff_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  286. or staff.staff_code LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  287. </if>
  288. <if test="ids != null and ids.size() > 0 ">
  289. order by case staff.staff_id
  290. <foreach collection="ids" index="index" item="item">
  291. when #{item}::uuid then #{item}::uuid
  292. </foreach>
  293. end
  294. </if>
  295. <if test="ids == null ">
  296. order by staff.staff_code
  297. </if>
  298. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  299. limit #{end} offset #{start}
  300. </if>
  301. </select>
  302. <!-- 查询表t_user,(条件查询)个数 -->
  303. <select id="getStaffCountByPage" resultType="Long">
  304. SELECT
  305. count(1)
  306. from dkic_b.t_mst_staff AS staff
  307. where staff.flg_valid
  308. and staff.cp_id =#{cpId}
  309. and staff.flg_ghost = false
  310. <if test="staffCode != null and staffCode != ''">
  311. And position (#{staffCode} in staff.staff_code)>0
  312. </if>
  313. <if test="staffName != null and staffName != ''">
  314. And position (#{staffName} in staff.staff_name)>0
  315. </if>
  316. </select>
  317. <!-- 函数查询单个系统参数-->
  318. <select id="getSettingValue" resultType="String">
  319. select dkic_b.f_get_setting_value(#{code}, #{cpId})
  320. </select>
  321. <!-- 函数查询所有系统参数-->
  322. <select id="getAllSettingValue" resultType="Map">
  323. select f_get_all_setting_value AS "setting" from dkic_b.f_get_all_setting_value(#{cpId})
  324. </select>
  325. <!-- 函数查询多个系统参数-->
  326. <select id="getSettingValues" resultType="Map">
  327. select core.f_get_setting_values(
  328. #{codes, typeHandler=StringListTypeHandler}, #{cpId})
  329. </select>
  330. <!-- 查询系统参数分类 -->
  331. <select id="getSettingKind" resultType="java.util.Map">
  332. select sk.kind_code as "classCode",
  333. sys.f_get_name_i18n_lang(sk.kind_name_i18n, #{i18n}) as "className",
  334. sk.display_no as "displayNo"
  335. from sys.t_setting_kind as sk
  336. where sk.flg_valid
  337. order by sk.display_no
  338. </select>
  339. <!-- 获取数据字典 -->
  340. <select id="getDictionaryData" resultType="java.util.Map">
  341. select dd.data_id as "dataId",
  342. dd.data_id as "id",
  343. dd.dict_code as "dictCode",
  344. dd.data_code as "dataCode",
  345. dd.data_value as "dataValue",
  346. dd.flg_default as "flgDefault"
  347. from dkic_b.t_mst_dictionary_data as dd
  348. where dd.flg_valid
  349. and dd.cp_id = #{cpId}
  350. and dd.dict_code = #{dictCode}
  351. <if test="searchText !=null">
  352. AND dd.data_value LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  353. </if>
  354. order by dd.display_no
  355. </select>
  356. <!-- 获取数据字典项目 -->
  357. <select id="getDictionaryItemData" resultType="java.util.Map">
  358. SELECT stdi.dict_code AS "dictCode",
  359. sys.f_get_name_i18n_lang(stdi.dict_name_i18n, #{i18n}) AS "dictName"
  360. FROM sys.t_dictionary_item stdi
  361. WHERE stdi.flg_valid
  362. AND stdi.level_no NOT IN ('1')
  363. </select>
  364. <!-- 获取数据类型 -->
  365. <select id="getValueKind" resultType="java.util.Map">
  366. select tvk.kind_code AS "kindCode",
  367. tvk.kind_name as "kindName",
  368. sys.f_get_name_i18n_lang(tvk.kind_name_i18n,#{i18n}) AS "kindLabel"
  369. from sys.t_value_kind as tvk
  370. where tvk.flg_valid
  371. <if test="used != null and used != ''">
  372. and #{used} = ANY (tvk.used)
  373. </if>
  374. order by tvk.display_no
  375. </select>
  376. <!-- 获取仓库 -->
  377. <select id="getWarehouse" resultType="java.util.Map">
  378. SELECT t.wh_id as "whId"
  379. , t.wh_id AS "id"
  380. , t.wh_name as "whName"
  381. , t.wh_code as "whCode"
  382. , t.flg_default as "flgDefault"
  383. FROM dkic_b.t_mst_warehouse t
  384. WHERE t.cp_id = #{cpId}
  385. and t.flg_valid
  386. <if test="whCode!=null and whCode!=''">
  387. and position(#{whCode} in t.wh_code) > 0
  388. </if>
  389. <if test="whName!=null and whName!=''">
  390. and position(#{whName} in t.wh_name) > 0
  391. </if>
  392. <!-- 部门上有仓库,只能选部门上的仓库;部门上没有仓库,可选所有仓库 -->
  393. <if test="orgId != null">
  394. and (select count(1)
  395. from dkic_b.t_mst_org_wh as tmow
  396. where tmow.org_id = #{orgId}::uuid) = 0
  397. or (exists(select 1
  398. from dkic_b.t_mst_org_wh as tmow
  399. where tmow.org_id = #{orgId}::uuid
  400. and tmow.wh_id = t.wh_id))
  401. </if>
  402. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  403. limit #{end} offset #{start}
  404. </if>
  405. </select>
  406. <!-- 获取商品 -->
  407. <select id="getGoods" resultType="java.util.Map">
  408. select tmgs.sku_id as "skuId",
  409. tmgs.sku_code as "skuCode",
  410. tmgs.sku_name as "skuName",
  411. tmgs.sku_model as "skuModel",
  412. tmgs.brand_id as "brandId",
  413. tmgb.brand_name as "brandName",
  414. tmgs.category_id as "categoryId",
  415. tmgc.cat_name as "categoryName",
  416. tmgs.unit_id as "unitId",
  417. tmgu.unit_name as "unitName",
  418. tmgs.sub_unit_id as "subUnitId",
  419. tmgs.conversion_factor as "conversionFactor",
  420. tmgs.series_id as "seriesId",
  421. tmgseries.series_name as "seriesName",
  422. tmgs.sku_spec as "skuSpec",
  423. tmgs.price_purchase as "pricePurchase",
  424. tmgs.price_standard as "priceStandard",
  425. tmgs.price_wholesale as "priceWholesale",
  426. tmgs.price_limited as "priceLimited",
  427. tmgs.sku_images as "skuImages",
  428. tmgs.remarks
  429. from dkic_b.t_mst_goods_sku as tmgs
  430. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  431. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  432. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  433. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  434. where tmgs.flg_valid
  435. AND tmgs.cp_id = #{cpId}
  436. <if test="skuCode != null">
  437. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  438. </if>
  439. <if test="skuName != null">
  440. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  441. </if>
  442. <if test="brandId != null">
  443. AND tmgs.brand_id = #{brandId} ::uuid
  444. </if>
  445. </select>
  446. <!-- 获取商品个数 -->
  447. <select id="getGoodsCountByPage" resultType="Long">
  448. SELECT
  449. count(1)
  450. from dkic_b.t_mst_goods_sku as tmgs
  451. where tmgs.flg_valid
  452. AND tmgs.cp_id = #{cpId}
  453. <if test="skuCode != null">
  454. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  455. </if>
  456. <if test="skuName != null">
  457. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  458. </if>
  459. </select>
  460. <!-- 获取商品 -->
  461. <select id="getGoodsForOrder" resultType="java.util.Map">
  462. select tmgs.sku_id as "skuId",
  463. tmgs.sku_code as "skuCode",
  464. tmgs.sku_name as "skuName",
  465. tmgs.sku_model as "skuModel",
  466. tmgs.brand_id as "brandId",
  467. tmgb.brand_name as "brandName",
  468. tmgb.short_name as "shortName",
  469. tmgs.category_id as "categoryId",
  470. tmgc.cat_name as "categoryName",
  471. tmgs.unit_id as "unitId",
  472. tmgu.unit_name as "unitName",
  473. tmgs.sub_unit_id as "subUnitId",
  474. tmgus.unit_name as "subUnitName",
  475. tmgs.flg_sub_unit as "flgSubUnit",
  476. tmgs.conversion_factor as "conversionFactor",
  477. tmgs.series_id as "seriesId",
  478. tmgseries.series_name as "seriesName",
  479. tmgs.sku_spec as "skuSpec",
  480. tmgs.price_purchase as "pricePurchase",
  481. tmgs.price_standard as "priceStandard",
  482. tmgs.price_wholesale as "priceWholesale",
  483. tmgs.price_other as "priceOther",
  484. tmgs.price_limited as "priceLimited",
  485. tmgs.sku_images as "skuImages",
  486. tmgs.remarks,
  487. tmgs.pack_box AS "packBox"
  488. ,tmgu.decimal_places as "decimalPlaces"
  489. ,tmgs.flg_price as "flgPrice"
  490. from dkic_b.t_mst_goods_sku as tmgs
  491. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  492. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  493. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  494. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  495. left join dkic_b.t_mst_unit as tmgus on tmgs.sub_unit_id = tmgus.unit_id
  496. where tmgs.flg_valid
  497. AND tmgs.cp_id = #{cpId}
  498. <if test="skuCode != null">
  499. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  500. </if>
  501. <if test="skuName != null">
  502. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  503. </if>
  504. <if test="brandId != null">
  505. AND tmgb.brand_id = #{brandId}::uuid
  506. </if>
  507. <if test="categoryId != null">
  508. AND tmgs.category_id = #{categoryId}::uuid
  509. </if>
  510. <if test="searchText != null">
  511. AND (tmgs.sku_model like concat('%', my_ex.likequery(#{searchText}) , '%')
  512. OR tmgs.sku_name like concat('%', my_ex.likequery(#{searchText}) , '%')
  513. )
  514. </if>
  515. </select>
  516. <!-- 获取商品个数 -->
  517. <select id="getGoodsForOrderCountByPage" resultType="Long">
  518. SELECT
  519. count(1)
  520. from dkic_b.t_mst_goods_sku as tmgs
  521. where tmgs.flg_valid
  522. AND tmgs.cp_id = #{cpId}
  523. <if test="skuCode != null">
  524. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  525. </if>
  526. <if test="skuName != null">
  527. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  528. </if>
  529. <if test="searchText != null">
  530. AND (tmgs.sku_model like concat('%', my_ex.likequery(#{searchText}) , '%')
  531. OR tmgs.sku_name like concat('%', my_ex.likequery(#{searchText}) , '%')
  532. )
  533. </if>
  534. </select>
  535. <!-- 获取商品(采购) -->
  536. <select id="getGoodsForPurchase" resultType="java.util.Map">
  537. select tmgs.sku_id as "skuId",
  538. tmgs.sku_code as "skuCode",
  539. tmgs.sku_name as "skuName",
  540. tmgs.sku_model as "skuModel",
  541. tmgs.brand_id as "brandId",
  542. tmgb.brand_name as "brandName",
  543. tmgs.category_id as "categoryId",
  544. tmgc.cat_name as "categoryName",
  545. tmgs.unit_id as "unitId",
  546. tmgu.unit_name as "unitName",
  547. tmgu.decimal_places as "decimalPlaces",
  548. tmgs.sub_unit_id as "subUnitId",
  549. tmgus.unit_name as "subUnitName",
  550. tmgs.conversion_factor as "conversionFactor",
  551. tmgs.series_id as "seriesId",
  552. tmgseries.series_name as "seriesName",
  553. tmgs.sku_spec as "skuSpec",
  554. tmgs.price_purchase as "pricePurchase",
  555. tmgs.price_standard as "priceStandard",
  556. tmgs.price_wholesale as "priceWholesale",
  557. tmgs.price_limited as "priceLimited",
  558. tmgs.sku_images as "skuImages",
  559. tmgs.pack_box as "packBox",
  560. tmgs.remarks
  561. from dkic_b.t_mst_goods_sku as tmgs
  562. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  563. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  564. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  565. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  566. left join dkic_b.t_mst_unit as tmgus on tmgs.sub_unit_id = tmgus.unit_id
  567. where tmgs.flg_valid
  568. AND tmgs.cp_id = #{cpId}
  569. <if test="skuCode != null">
  570. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  571. </if>
  572. <if test="skuName != null">
  573. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  574. </if>
  575. <if test="skuModel != null">
  576. AND tmgs.sku_model LIKE concat('%',my_ex.likequery(#{skuModel}),'%')
  577. </if>
  578. </select>
  579. <!-- 获取商品个数(采购) -->
  580. <select id="getGoodsForPurchaseCountByPage" resultType="Long">
  581. SELECT
  582. count(1)
  583. from dkic_b.t_mst_goods_sku as tmgs
  584. where tmgs.flg_valid
  585. AND tmgs.cp_id = #{cpId}
  586. <if test="skuCode != null">
  587. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  588. </if>
  589. <if test="skuName != null">
  590. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  591. </if>
  592. </select>
  593. <!-- 获取客户 -->
  594. <select id="getCustomer" resultType="java.util.Map">
  595. select tmc.cus_id as "cusId",
  596. tmc.cus_code as "cusCode",
  597. tmc.cus_name as "cusName",
  598. tmc.cus_phone as "cusPhone",
  599. tmc.address_area as "addressArea",
  600. tmc.address_name as "addressName",
  601. tmc.address_no as "addressNo",
  602. tmc.address_gcj02 as "addressGcj02",
  603. tmc.address_full as "addressFull",
  604. tmc.contact_name as "contactName",
  605. tmc.contact_phone as "contactPhone",
  606. tmc.cus_from as "cusFrom",
  607. tmdd.data_value as "cusFromName",
  608. tmc.channel_id as "channelId",
  609. tmsc.channel_name as "channelName",
  610. tmc.org_id as "orgId",
  611. tmo.org_name as "orgName",
  612. tmc.staff_id as "staffId",
  613. tms.staff_name as "staffName",
  614. tmc.report_staff as "reportStaff",
  615. reportstaff.staff_name as "reportStaffName",
  616. tmc.report_time as "reportTime",
  617. tmc.sale_status as "saleStatus",
  618. tmc.remarks as "remarks",
  619. tmc.follow_staffs as "followStaffs",
  620. tmc.last_follow_staff as "lastFollowStaff",
  621. tmc.last_follow_id as "lastFollowId",
  622. tmc.last_follow_status as "lastFollowStatus",
  623. tmc.last_follow_time as "lastFollowTime"
  624. from dkic_b.t_mst_customer as tmc
  625. left join dkic_b.t_mst_org tmo on tmc.org_id = tmo.org_id
  626. left join dkic_b.t_mst_staff tms on tmc.staff_id = tms.staff_id
  627. left join dkic_b.t_mst_staff as reportstaff on tmc.report_staff = reportstaff.staff_id
  628. left join dkic_b.t_mst_sale_channel tmsc on tmc.channel_id = tmsc.channel_id
  629. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  630. where tmc.flg_valid
  631. AND tmc.cp_id = #{cpId}
  632. <if test="skuCode != null">
  633. AND tmc.cus_code = #{cusCode}
  634. </if>
  635. <if test="skuName != null">
  636. AND tmc.cus_name = #{cusName}
  637. </if>
  638. </select>
  639. <!-- 获取客户个数 -->
  640. <select id="getCustomerCountByPage" resultType="Long">
  641. SELECT
  642. count(1)
  643. from dkic_b.t_mst_customer as tmc
  644. where tmc.flg_valid
  645. and tmc.cp_id = #{cpId}
  646. <if test="skuCode != null">
  647. AND tmc.cus_code = #{cusCode}
  648. </if>
  649. <if test="skuName != null">
  650. AND tmc.cus_name = #{cusName}
  651. </if>
  652. </select>
  653. <!-- 获取单据Id-->
  654. <select id="getUuidSeq" resultType="object">
  655. select sys.f_uuid_seq()
  656. </select>
  657. <!-- 获取单据单号-->
  658. <select id="getDocNo" resultType="java.lang.String">
  659. select dkic_b.f_create_note(#{cpId}, #{purId}::uuid, #{docCode})
  660. </select>
  661. <!--获取供应商-->
  662. <select id="getSupplier" resultType="java.util.Map">
  663. select tms.sup_code as "supplierCode",
  664. tms.sup_name as "supplierName",
  665. tms.sup_id as "supplierId",
  666. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "supplierType",
  667. tms.contact_name as "contactName",
  668. tms.contact_phone as "contactPhone",
  669. tms.flg_valid as "flgValid"
  670. from dkic_b.t_mst_supplier tms
  671. LEFT JOIN sys.t_data_kind tdk
  672. ON tdk.kind_code = tms.sup_type
  673. where tms.cp_id = #{cpId}
  674. <if test="supplierName!=null and supplierName!=''">
  675. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{supplierName}),'%')
  676. </if>
  677. <if test="supplierCode!=null and supplierCode!=''">
  678. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{supplierCode}),'%')
  679. </if>
  680. <if test="supplierType!=null and supplierType!=''">
  681. AND tms.sup_type = #{supplierType}
  682. </if>
  683. order by tms.sup_code
  684. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  685. limit #{end} offset #{start}
  686. </if>
  687. <if test="limit != null and limit != 0 ">
  688. limit #{limit}
  689. </if>
  690. </select>
  691. <!--获取供应商数量-->
  692. <select id="countSupplier" resultType="java.lang.Long">
  693. select count(1)
  694. from dkic_b.t_mst_supplier tms
  695. LEFT JOIN sys.t_data_kind tdk
  696. ON tdk.kind_code = tms.sup_type
  697. where tms.cp_id = #{cpId}
  698. <if test="supplierName!=null and supplierName!=''">
  699. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{supplierName}),'%')
  700. </if>
  701. <if test="supplierCode!=null and supplierCode!=''">
  702. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{supplierCode}),'%')
  703. </if>
  704. <if test="supplierType!=null and supplierType!=''">
  705. AND tms.sup_type LIKE concat('%',my_ex.likequery(#{supplierType}),'%')
  706. </if>
  707. </select>
  708. <!--获取渠道 -->
  709. <select id="getChannel" resultType="java.util.Map">
  710. select c.channel_id as "channelId",
  711. c.channel_code as "channelCode",
  712. c.channel_name as "channelName",
  713. c.sys_code as "sysCode",
  714. c.display_no as "displayNo"
  715. from dkic_b.t_mst_sale_channel as c
  716. where c.flg_valid
  717. and c.cp_id = #{cpId}
  718. <if test="channel_code!=null and channel_code!=''">
  719. AND c.channel_code LIKE concat('%', #{channelCode}, '%')
  720. </if>
  721. <if test="channel_name!=null and channel_name!=''">
  722. AND c.channel_name LIKE concat('%', #{channelName}, '%')
  723. </if>
  724. order by c.display_no
  725. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  726. limit #{end} offset #{start}
  727. </if>
  728. <if test="limit != null and limit != 0 ">
  729. limit #{limit}
  730. </if>
  731. </select>
  732. <!-- 查询商品档案-->
  733. <select id="getGoodsBrand" resultType="java.util.Map">
  734. SELECT
  735. tmgb.flg_valid AS "flgValid",
  736. tmgb.brand_id AS "brandId", tmgb.brand_code AS "brandCode", tmgb.brand_name AS "brandName",
  737. (SELECT COALESCE(array_to_string(array_agg(tsm.sup_name), ','),'')
  738. FROM dkic_b.t_mst_supplier_brand tsmb
  739. left join dkic_b.t_mst_supplier tsm on tsm.sup_id = tsmb.sup_id
  740. WHERE tsmb.brand_id = tmgb.brand_id) AS "supplierName"
  741. FROM dkic_b.t_mst_goods_brand tmgb
  742. <where>
  743. <if test="searchText !=null">
  744. AND tmgb.brand_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  745. </if>
  746. <if test="cpId != null">
  747. AND tmgb.cp_id = #{cpId}
  748. </if>
  749. <if test="flgValid != null">
  750. AND tmgb.flg_valid = #{flgValid}
  751. </if>
  752. </where>
  753. order by tmgb.display_no asc
  754. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  755. limit #{end} offset #{start}
  756. </if>
  757. </select>
  758. <!-- 查询商品种类-->
  759. <select id="getGoodsCategoryTree" resultType="java.util.Map">
  760. SELECT
  761. T.cat_id AS "catId",
  762. T.cat_code AS "catCode",
  763. T.cat_name AS "catName",
  764. T.parent_id AS "parentId",
  765. T.flg_valid AS "flgValid"
  766. FROM
  767. (--当前数据
  768. SELECT
  769. tmgc.cat_id,
  770. tmgc.cat_code,
  771. tmgc.cat_name,
  772. tmgc.parent_id,
  773. tmgc.flg_valid
  774. FROM
  775. dkic_b.t_mst_goods_category tmgc
  776. <where>
  777. <if test="searchText !=null">
  778. AND ( tmgc.cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  779. or tmgc.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  780. </if>
  781. <if test="cpId != null">
  782. AND tmgc.cp_id = #{cpId}
  783. </if>
  784. AND tmgc.flg_valid
  785. </where>
  786. UNION ALL--父级
  787. SELECT
  788. tmgcp.cat_id,
  789. tmgcp.cat_code,
  790. tmgcp.cat_name,
  791. tmgcp.parent_id,
  792. tmgcp.flg_valid
  793. FROM
  794. dkic_b.t_mst_goods_category tmgc
  795. LEFT JOIN dkic_b.t_mst_goods_category tmgcp ON tmgc.cat_id = ANY ( tmgcp.level_lower )
  796. <where>
  797. <if test="searchText !=null">
  798. AND ( tmgc.cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  799. or tmgc.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  800. </if>
  801. <if test="cpId != null">
  802. AND tmgc.cp_id = #{cpId}
  803. </if>
  804. AND tmgc.flg_valid
  805. </where>
  806. ) T
  807. WHERE T.cat_id IS NOT NULL
  808. GROUP BY
  809. T.cat_id,
  810. T.cat_code,
  811. T.cat_name,
  812. T.parent_id,
  813. T.flg_valid
  814. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  815. limit #{end} offset #{start}
  816. </if>
  817. </select>
  818. <!-- 查询表t_mst_goods_brand,(条件查询)个数 -->
  819. <select id="countGoodsBrand" resultType="Long">
  820. SELECT
  821. count(1)
  822. FROM dkic_b.t_mst_goods_brand tmgb
  823. <where>
  824. <if test="searchText !=null">
  825. AND tmgb.brand_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  826. </if>
  827. <if test="cpId != null">
  828. AND tmgb.cp_id = #{cpId}
  829. </if>
  830. <if test="flgValid != null">
  831. AND tmgb.flg_valid = #{flgValid}
  832. </if>
  833. </where>
  834. </select>
  835. <!-- 查询商品种类-->
  836. <select id="getGoodsCategory" resultType="java.util.Map">
  837. SELECT
  838. cat_id AS "catId",
  839. cat_code AS "catCode",
  840. cat_name AS "catName",
  841. parent_id AS "parentId",
  842. flg_valid AS "flgValid"
  843. FROM dkic_b.t_mst_goods_category
  844. <where>
  845. <if test="searchText !=null">
  846. AND ( cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  847. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  848. </if>
  849. <if test="cpId != null">
  850. AND cp_id = #{cpId}
  851. </if>
  852. </where>
  853. ORDER BY display_no
  854. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  855. limit #{end} offset #{start}
  856. </if>
  857. </select>
  858. <!-- 查询商品种类的个数-->
  859. <select id="countGoodsCategory" resultType="java.lang.Long">
  860. SELECT
  861. count(1)
  862. FROM dkic_b.t_mst_goods_category
  863. <where>
  864. <if test="searchText !=null">
  865. AND ( cat_name LIKE concat('%', #{searchText}, '%')
  866. or remarks LIKE concat('%', #{searchText}, '%'))
  867. </if>
  868. <if test="cpId != null">
  869. AND cp_id = #{cpId}
  870. </if>
  871. </where>
  872. </select>
  873. <!-- 查询商品系列-->
  874. <select id="getGoodsSeries" resultType="java.util.Map">
  875. SELECT
  876. series_id AS "seriesId",
  877. series_code AS "seriesCode",
  878. series_name AS "seriesName",
  879. flg_valid AS "flgValid"
  880. FROM dkic_b.t_mst_goods_series
  881. <where>
  882. <if test="searchText !=null">
  883. AND ( series_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  884. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  885. </if>
  886. <if test="cpId != null">
  887. AND cp_id = #{cpId}
  888. </if>
  889. AND flg_valid
  890. </where>
  891. order by display_no asc
  892. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  893. limit #{end} offset #{start}
  894. </if>
  895. </select>
  896. <!-- 商品系列个数-->
  897. <select id="countGoodsSeries" resultType="java.lang.Long">
  898. SELECT
  899. count(1)
  900. FROM dkic_b.t_mst_goods_series
  901. <where>
  902. <if test="searchText !=null">
  903. AND ( series_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  904. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  905. </if>
  906. <if test="cpId != null">
  907. AND cp_id = #{cpId}
  908. </if>
  909. </where>
  910. </select>
  911. <!-- 获取计量单位-->
  912. <select id="getUnit" resultType="java.util.Map">
  913. SELECT
  914. unit_id AS "unitId",
  915. unit_code AS "unitCode",
  916. unit_name AS "unitName",
  917. decimal_places AS "decimalPlaces",
  918. flg_valid AS "flgValid"
  919. FROM dkic_b.t_mst_unit
  920. <where>
  921. <if test="searchText !=null">
  922. AND ( unit_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  923. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  924. </if>
  925. <if test="cpId != null">
  926. AND cp_id = #{cpId}
  927. </if>
  928. AND flg_valid
  929. </where>
  930. order by display_no asc
  931. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  932. limit #{end} offset #{start}
  933. </if>
  934. </select>
  935. <!-- 获取计量单位个数-->
  936. <select id="countUnit" resultType="java.lang.Long">
  937. SELECT
  938. count(1)
  939. FROM dkic_b.t_mst_unit
  940. <where>
  941. <if test="searchText !=null">
  942. AND ( unit_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  943. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  944. </if>
  945. <if test="cpId != null">
  946. AND cp_id = #{cpId}
  947. </if>
  948. </where>
  949. </select>
  950. <!--获取仓库档案-->
  951. <select id="getWarehouseByPage" resultType="java.util.Map">
  952. SELECT t.wh_id AS "whId",
  953. t.wh_code AS "whCode",
  954. t.wh_name AS "whName",
  955. t.supervisor AS "supervisor",
  956. t.contact_phone AS "contactPhone",
  957. t.flg_valid AS "flgValid"
  958. FROM dkic_b.t_mst_warehouse as t
  959. <where>
  960. <if test="searchText !=null">
  961. AND ( t.wh_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  962. or t.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  963. </if>
  964. <if test="cpId != null">
  965. AND t.cp_id = #{cpId}
  966. </if>
  967. <if test="flgValid != null">
  968. AND t.flg_valid = #{flgValid}
  969. </if>
  970. <!-- 部门上有仓库,只能选部门上的仓库;部门上没有仓库,可选所有仓库 -->
  971. <if test="orgId != null">
  972. and (select count(1)
  973. from dkic_b.t_mst_org_wh as tmow
  974. where tmow.org_id = #{orgId}::uuid) = 0
  975. or (exists(select 1
  976. from dkic_b.t_mst_org_wh as tmow
  977. where tmow.org_id = #{orgId}::uuid
  978. and tmow.wh_id = t.wh_id))
  979. </if>
  980. </where>
  981. order by display_no asc
  982. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  983. limit #{end} offset #{start}
  984. </if>
  985. </select>
  986. <!--获取仓库档案个数-->
  987. <select id="countWarehouseByPage" resultType="Long">
  988. SELECT count(1)
  989. FROM dkic_b.t_mst_warehouse as t
  990. <where>
  991. <if test="searchText !=null">
  992. AND ( t.wh_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  993. or t.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  994. </if>
  995. <if test="cpId != null">
  996. AND t.cp_id = #{cpId}
  997. </if>
  998. <!-- 部门上有仓库,只能选部门上的仓库;部门上没有仓库,可选所有仓库 -->
  999. <if test="orgId != null">
  1000. and (select count(1)
  1001. from dkic_b.t_mst_org_wh as tmow
  1002. where tmow.org_id = #{orgId}::uuid) = 0
  1003. or (exists(select 1
  1004. from dkic_b.t_mst_org_wh as tmow
  1005. where tmow.org_id = #{orgId}::uuid
  1006. and tmow.wh_id = t.wh_id))
  1007. </if>
  1008. </where>
  1009. </select>
  1010. <!-- 查询库存 -->
  1011. <select id="getInventory" resultType="java.util.Map">
  1012. select tpi.inv_id as "invId",
  1013. tpi.sku_id as "skuId",
  1014. tmgs.sku_code as "skuCode",
  1015. tmgs.sku_name as "skuName",
  1016. tmgs.sku_model as "skuModel",
  1017. tmgs.brand_id as "brandId",
  1018. tmgb.brand_name as "brandName",
  1019. tmgs.category_id as "categoryId",
  1020. tmgc.cat_name as "categoryName",
  1021. tmgs.unit_id as "unitId",
  1022. tmgs.sub_unit_id as "subUnitId",
  1023. tmgs.conversion_factor as "conversionFactor",
  1024. tmgs.series_id as "seriesId",
  1025. tmgseries.series_name as "seriesName",
  1026. tmgs.sku_spec as "skuSpec",
  1027. tmgs.price_purchase as "pricePurchase",
  1028. tmgs.price_standard as "priceStandard",
  1029. tmgs.price_wholesale as "priceWholesale",
  1030. tmgs.price_limited as "priceLimited",
  1031. tmgs.sku_images as "skuImages",
  1032. tpi.non_std_code as "nonStdCode",
  1033. tpi.inv_qty as "invQty",
  1034. tpi.outing_qty as "outingQty",
  1035. tpi.freeze_qty as "freezeQty",
  1036. tpi.usable_qty as "usableQty",
  1037. tpi.wh_id as "whId",
  1038. tmw.wh_code as "whCode",
  1039. tmw.wh_name as "whName",
  1040. tmgs.pack_box as "packBox",
  1041. tmgs.unit_id as "unitId",
  1042. tmgs.sub_unit_id as "subUnitId",
  1043. ul.unit_name as "unitName",
  1044. u2.unit_name as "subUnitName",
  1045. dkic_b.f_get_last_ivt_price(tpi.inv_id,null,null,null) as "priceInto",
  1046. tpi.remarks
  1047. from dkic_b.t_psi_inventory as tpi
  1048. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1049. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  1050. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  1051. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  1052. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  1053. left join dkic_b.t_mst_unit as ul on tmgs.unit_id = ul.unit_id
  1054. left join dkic_b.t_mst_unit as u2 on tmgs.sub_unit_id = u2.unit_id
  1055. where tpi.flg_valid
  1056. AND tpi.cp_id = #{cpId}
  1057. <if test="skuId != null">
  1058. AND tpi.sku_id = #{skuId} ::uuid
  1059. </if>
  1060. <if test="nonStdCode != null">
  1061. AND tpi.non_std_code = #{nonStdCode}
  1062. </if>
  1063. <if test="skuCode != null">
  1064. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1065. </if>
  1066. <if test="skuName != null">
  1067. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1068. </if>
  1069. <if test="whName != null">
  1070. AND tmw.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1071. </if>
  1072. <if test="whId != null">
  1073. AND tpi.wh_id = #{whId} ::uuid
  1074. </if>
  1075. <if test="inqtyFlag != null">
  1076. AND tpi.inv_qty != 0
  1077. </if>
  1078. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1079. limit #{end} offset #{start}
  1080. </if>
  1081. </select>
  1082. <!-- 查询库存个数 -->
  1083. <select id="getInventoryCountByPage" resultType="Long">
  1084. SELECT
  1085. count(1)
  1086. from dkic_b.t_psi_inventory as tpi
  1087. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1088. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  1089. where tpi.flg_valid
  1090. AND tpi.cp_id = #{cpId}
  1091. <if test="skuId != null">
  1092. AND tpi.sku_id = #{skuId} ::uuid
  1093. </if>
  1094. <if test="nonStdCode != null">
  1095. AND tpi.non_std_code = #{nonStdCode}
  1096. </if>
  1097. <if test="skuCode != null">
  1098. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1099. </if>
  1100. <if test="skuName != null">
  1101. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1102. </if>
  1103. <if test="whName != null">
  1104. AND tmgs.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1105. </if>
  1106. </select>
  1107. <!-- 获取销售渠道-->
  1108. <select id="getSaleChannel" resultType="java.util.Map">
  1109. SELECT
  1110. channel_id AS "channelId",
  1111. channel_id AS "id",
  1112. channel_code AS "channelCode",
  1113. channel_name AS "channelName"
  1114. FROM dkic_b.t_mst_sale_channel
  1115. <where>
  1116. flg_valid
  1117. <if test="cpId != null">
  1118. AND cp_id = #{cpId}
  1119. </if>
  1120. order by display_no
  1121. </where>
  1122. </select>
  1123. <!--获取结算方式数据-->
  1124. <select id="getSettlement" resultType="java.util.Map">
  1125. SELECT T.mac_id id,
  1126. T.mac_code AS "macCode",
  1127. T.mac_name AS "macName",
  1128. T.mac_Type,
  1129. dd.data_value AS "macTypeName",
  1130. T.balance,
  1131. T.display_no,
  1132. T.mac_receipt_code,
  1133. T.acc_date,
  1134. T.flg_negative,
  1135. T.remarks,
  1136. T.flg_valid,
  1137. T.cp_id,
  1138. COALESCE ( tmti.amt_trf, 0 ) AS "initBalance"
  1139. FROM
  1140. dkic_b.t_mst_money_account
  1141. AS T LEFT JOIN dkic_b.t_mst_dictionary_data AS dd ON T.mac_type = dd.data_id
  1142. LEFT JOIN (
  1143. SELECT
  1144. tmti.trf_in_mac,
  1145. tmti.amt_trf
  1146. FROM
  1147. dkic_b.t_mac_transfer AS tmt
  1148. INNER JOIN dkic_b.t_mac_transfer_item AS tmti ON tmti.trf_id = tmt.trf_id
  1149. AND tmt.flg_valid
  1150. AND tmti.flg_valid
  1151. AND tmt.trf_type = 0
  1152. ) tmti ON tmti.trf_in_mac = T.mac_id
  1153. WHERE
  1154. T.cp_id = #{cpId}
  1155. and t.flg_valid
  1156. ORDER BY
  1157. T.display_no
  1158. </select>
  1159. <!-- 获取销售渠道-->
  1160. <select id="getSaleChannelPurviewType" resultType="java.util.Map">
  1161. SELECT
  1162. sc.channel_id AS "channelId",
  1163. sc.channel_id AS "id",
  1164. sc.channel_code AS "channelCode",
  1165. sc.channel_name AS "channelName",
  1166. COALESCE ( ( SELECT flg_nolimit FROM dkic_b.t_mst_staff_purview WHERE staff_id = #{staffId} :: UUID and purview_code = #{purviewCode}), FALSE ) "flgNolimit",
  1167. CASE WHEN scsc.channel_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
  1168. FROM dkic_b.t_mst_sale_channel sc
  1169. left JOIN dkic_b.t_mst_sale_channel scsc ON scsc.channel_id = sc.channel_id and sc.channel_id::uuid = any ( (
  1170. select data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid and purview_code = #{purviewCode})::uuid[])
  1171. <where>
  1172. sc.flg_valid
  1173. <if test="cpId != null">
  1174. AND sc.cp_id = #{cpId}
  1175. </if>
  1176. <if test="channelCode !=null and channelCode !=''">
  1177. AND sc.channel_code LIKE concat('%',my_ex.likequery(#{channelCode}),'%')
  1178. </if>
  1179. <if test="channelName !=null and channelName !=''">
  1180. AND sc.channel_name LIKE concat('%',my_ex.likequery(#{channelName}),'%')
  1181. </if>
  1182. order by sc.display_no
  1183. </where>
  1184. </select>
  1185. <!--获取仓库档案-->
  1186. <!--获取供应商和客户数据-->
  1187. <select id="getSupplierAndCustomer" resultType="java.util.Map">
  1188. select tms.sup_id as "objId",
  1189. tms.sup_code as "objCode",
  1190. tms.sup_name as "objName",
  1191. '供应商' as "objTypeName",
  1192. 1 as "objType",
  1193. tms.flg_valid as "flgValid"
  1194. null as "phone",
  1195. null as "addressFull"
  1196. from dkic_b.t_mst_supplier tms
  1197. <where>
  1198. <if test="flgValid">
  1199. AND tms.flg_valid
  1200. </if>
  1201. <if test="objCode != null and objCode != ''">
  1202. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1203. </if>
  1204. <if test="objName != null and objName != ''">
  1205. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1206. </if>
  1207. </where>
  1208. union all
  1209. select cus.cus_id as "objId",
  1210. cus.cus_code as "objCode",
  1211. cus.cus_name as "objName",
  1212. '客户' as "objTypeName",
  1213. 2 as "objType",
  1214. cus.flg_valid as "flgValid",
  1215. cus.cus_phone as "phone",
  1216. cus.address_full as "addressFull"
  1217. from dkic_b.t_mst_customer cus
  1218. <where>
  1219. <if test="flgValid">
  1220. AND cus.flg_valid
  1221. </if>
  1222. <if test="objCode != null and objCode != ''">
  1223. AND cus.cus_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1224. </if>
  1225. <if test="objName != null and objName != ''">
  1226. AND cus.cus_name LIKE concat('%',my_ex.likequery(#{objName}),'%')
  1227. </if>
  1228. </where>
  1229. </select>
  1230. <!--获取供应商和客户数据分页-->
  1231. <select id="getSupplierAndCustomerByPage" resultType="java.util.Map">
  1232. select * from (
  1233. select tms.sup_id as "objId",
  1234. tms.sup_code as "objCode",
  1235. tms.sup_name as "objName",
  1236. '供应商' as "objTypeName",
  1237. 1 as "objType",
  1238. tms.flg_valid as "flgValid",
  1239. tms.contact_phone as "phone",
  1240. tms.return_address as "addressFull"
  1241. from dkic_b.t_mst_supplier tms
  1242. <where >
  1243. tms.sup_type = '供应商类别-采购'
  1244. and tms.cp_id = #{cpId}
  1245. <if test="flgValid">
  1246. AND tms.flg_valid
  1247. </if>
  1248. <if test="objCode != null and objCode != ''">
  1249. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1250. </if>
  1251. <if test="objName != null and objName != ''">
  1252. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1253. </if>
  1254. <if test="searchText != null and searchText != ''">
  1255. AND (
  1256. tms.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1257. or tms.contact_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1258. or tms.return_address LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1259. )
  1260. </if>
  1261. </where>
  1262. union all
  1263. select cus.cus_id as "objId",
  1264. cus.cus_code as "objCode",
  1265. cus.cus_name as "objName",
  1266. '客户' as "objTypeName",
  1267. 2 as "objType",
  1268. cus.flg_valid as "flgValid",
  1269. cus.cus_phone as "phone",
  1270. cus.address_full as "addressFull"
  1271. from dkic_b.t_mst_customer cus
  1272. <where>
  1273. cus.cp_id = #{cpId}
  1274. <if test="flgValid">
  1275. AND cus.flg_valid
  1276. </if>
  1277. <if test="objCode != null and objCode != ''">
  1278. AND cus.cus_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1279. </if>
  1280. <if test="objName != null and objName != ''">
  1281. AND cus.cus_name LIKE concat('%',my_ex.likequery(#{objName}),'%')
  1282. </if>
  1283. <if test="searchText != null and searchText != ''">
  1284. AND ( cus.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1285. or cus.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1286. or cus.address_full LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1287. )
  1288. </if>
  1289. </where>
  1290. ) tt
  1291. <where>
  1292. <if test="objType != null and objType != ''">
  1293. AND tt."objType" = #{objType}
  1294. </if>
  1295. </where>
  1296. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1297. limit #{end} offset #{start}
  1298. </if>
  1299. </select>
  1300. <!--获取供应商和客户数据分页-->
  1301. <select id="getSupplierAndCustomerByPageCount" resultType="Long">
  1302. select count(1) from(
  1303. select tms.sup_id as "objId",
  1304. tms.sup_code as "objCode",
  1305. tms.sup_name as "objName",
  1306. '供应商' as "objTypeName",
  1307. 1 as "objType",
  1308. tms.flg_valid as "flgValid",
  1309. null as "phone",
  1310. null as "addressFull"
  1311. from dkic_b.t_mst_supplier tms
  1312. <where>
  1313. tms.sup_type = '供应商类别-采购'
  1314. and tms.cp_id = #{cpId}
  1315. <if test="flgValid">
  1316. AND tms.flg_valid
  1317. </if>
  1318. <if test="objCode != null and objCode != ''">
  1319. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1320. </if>
  1321. <if test="objName != null and objName != ''">
  1322. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1323. </if>
  1324. <if test="searchText != null and searchText != ''">
  1325. AND (
  1326. tms.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1327. or tms.contact_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1328. or tms.return_address LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1329. )
  1330. </if>
  1331. </where>
  1332. union all
  1333. select cus.cus_id as "objId",
  1334. cus.cus_code as "objCode",
  1335. cus.cus_name as "objName",
  1336. '客户' as "objTypeName",
  1337. 2 as "objType",
  1338. cus.flg_valid as "flgValid",
  1339. cus.cus_phone as "phone",
  1340. cus.address_full as "addressFull"
  1341. from dkic_b.t_mst_customer cus
  1342. <where>
  1343. and cus.cp_id = #{cpId}
  1344. <if test="flgValid">
  1345. AND cus.flg_valid
  1346. </if>
  1347. <if test="objCode != null and objCode != ''">
  1348. AND cus.cus_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1349. </if>
  1350. <if test="objName != null and objName != ''">
  1351. AND cus.cus_name LIKE concat('%',my_ex.likequery(#{objName}),'%')
  1352. </if>
  1353. <if test="searchText != null and searchText != ''">
  1354. AND ( cus.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1355. or cus.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1356. or cus.address_full LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1357. )
  1358. </if>
  1359. </where>
  1360. ) tt
  1361. <where>
  1362. <if test="objType != null and objType != ''">
  1363. AND tt."objType" = #{objType}
  1364. </if>
  1365. </where>
  1366. </select>
  1367. <!-- 获取用户 -->
  1368. <select id="getStaff" resultType="java.util.Map">
  1369. select
  1370. s.staff_name as "staffName"
  1371. , s.staff_code as "staffCode"
  1372. , sys.f_code_name(s.staff_code, s.staff_name) AS "staffCodeName"
  1373. , s.staff_id as "staffId"
  1374. , s.staff_id AS "id"
  1375. , s.org_id as "orgId"
  1376. , o.org_name as "orgName"
  1377. , c.cp_name as "cpName"
  1378. FROM dkic_b.t_mst_staff s
  1379. left join dkic_b.t_mst_org o on o.org_id = s.org_id
  1380. left join dkic_a.t_a_company c on c.cp_id = s.cp_id
  1381. where
  1382. s.flg_valid
  1383. and s.hr_status = 1
  1384. and s.cp_id = #{cpId}
  1385. and s.flg_ghost = false
  1386. <if test="staffCode !=null and staffCode !=''">
  1387. AND s.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
  1388. </if>
  1389. <if test="staffName !=null and staffName !=''">
  1390. AND s.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  1391. </if>
  1392. <if test="orgId !=null">
  1393. AND s.org_id = #{orgId}
  1394. </if>
  1395. <if test="orgName !=null and orgName !=''">
  1396. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1397. </if>
  1398. </select>
  1399. <!-- 获取用户 -->
  1400. <select id="getStaffPurviewType" resultType="java.util.Map">
  1401. select
  1402. s.staff_name as "staffName"
  1403. , s.staff_code as "staffCode"
  1404. , s.staff_id as "staffId",
  1405. COALESCE ( ( SELECT flg_nolimit FROM dkic_b.t_mst_staff_purview WHERE staff_id = #{staffId} :: UUID and purview_code = #{purviewCode}), FALSE ) "flgNolimit",
  1406. CASE WHEN ss.staff_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
  1407. FROM dkic_b.t_mst_staff s
  1408. left JOIN dkic_b.t_mst_staff ss ON ss.staff_id = s.staff_id and s.staff_id::uuid = any ( (
  1409. select data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid and purview_code = #{purviewCode})::uuid[])
  1410. where
  1411. s.flg_valid
  1412. and s.hr_status = 1
  1413. and s.cp_id = #{cpId}
  1414. and s.flg_ghost = false
  1415. <if test="staffCode !=null and staffCode !=''">
  1416. AND s.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
  1417. </if>
  1418. <if test="staffName !=null and staffName !=''">
  1419. AND s.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  1420. </if>
  1421. </select>
  1422. <!-- 获取组织机构 -->
  1423. <select id="getOrganization" resultType="java.util.Map">
  1424. select o.org_id as "orgId"
  1425. , o.org_code as "orgCode"
  1426. , o.org_name as "orgName"
  1427. , sys.f_code_name(o.org_code, o.org_name) AS "orgCodeName"
  1428. from dkic_b.t_mst_org o
  1429. where
  1430. o.flg_valid
  1431. and o.cp_id = #{cpId}
  1432. <if test="orgCode !=null and orgCode !=''">
  1433. AND o.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1434. </if>
  1435. <if test="orgName !=null and orgName !=''">
  1436. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1437. </if>
  1438. order by o.level_code
  1439. </select>
  1440. <!-- 获取组织机构分页 -->
  1441. <select id="getOrganizationByPage" resultType="java.util.Map">
  1442. select o.org_id as "orgId"
  1443. , o.org_code as "orgCode"
  1444. , o.org_name as "orgName"
  1445. , sys.f_code_name(o.org_code, o.org_name) AS "orgCodeName"
  1446. from dkic_b.t_mst_org o
  1447. where
  1448. o.flg_valid
  1449. and o.cp_id = #{cpId}
  1450. <if test="orgCode !=null and orgCode !=''">
  1451. AND o.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1452. </if>
  1453. <if test="orgName !=null and orgName !=''">
  1454. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1455. </if>
  1456. order by o.level_code
  1457. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1458. limit #{end} offset #{start}
  1459. </if>
  1460. </select>
  1461. <!-- 获取组织机构分个数-->
  1462. <select id="getOrganizationCount" resultType="java.lang.Long">
  1463. SELECT count(1)
  1464. from dkic_b.t_mst_org o
  1465. where
  1466. o.flg_valid
  1467. and o.cp_id = #{cpId}
  1468. <if test="orgCode !=null and orgCode !=''">
  1469. AND o.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1470. </if>
  1471. <if test="orgName !=null and orgName !=''">
  1472. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1473. </if>
  1474. </select>
  1475. <!-- 获取资金账户(下拉)-->
  1476. <select id="getMac" resultType="java.util.Map">
  1477. select tmma.mac_id as "macId",
  1478. tmma.mac_code as "macCode",
  1479. tmma.mac_name as "macName",
  1480. tmma.mac_type as "macType",
  1481. tmma.balance,
  1482. tmma.display_no as "displayNo",
  1483. tmma.flg_default as "flgDefault",
  1484. tmma.mac_receipt_code as "macReceiptCode",
  1485. tmma.remarks
  1486. from dkic_b.t_mst_money_account tmma
  1487. where tmma.flg_valid
  1488. and tmma.cp_id = #{cpId}
  1489. <if test="macCode !=null and macCode !=''">
  1490. AND tmma.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1491. </if>
  1492. <if test="macName !=null and macName !=''">
  1493. AND tmma.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1494. </if>
  1495. order by tmma.display_no
  1496. </select>
  1497. <!-- 获取资金账户(放大镜) -->
  1498. <select id="getMoneyAccount" resultType="java.util.Map">
  1499. select tmma.mac_id as "macId",
  1500. tmma.mac_code as "macCode",
  1501. tmma.mac_name as "macName",
  1502. tmma.mac_type as "macType",
  1503. tmma.balance,
  1504. tmma.display_no as "displayNo",
  1505. tmma.flg_default as "flgDefault",
  1506. tmma.mac_receipt_code as "macReceiptCode",
  1507. tmma.remarks
  1508. from dkic_b.t_mst_money_account tmma
  1509. where tmma.flg_valid
  1510. and tmma.cp_id = #{cpId}
  1511. <if test="macCode !=null and macCode !=''">
  1512. AND tmma.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1513. </if>
  1514. <if test="macName !=null and macName !=''">
  1515. AND tmma.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1516. </if>
  1517. order by tmma.display_no
  1518. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1519. limit #{end} offset #{start}
  1520. </if>
  1521. </select>
  1522. <!-- 获取资金账户(放大镜)个数 -->
  1523. <select id="getMoneyAccountCountByPage" resultType="Long">
  1524. SELECT
  1525. count(1)
  1526. from dkic_b.t_mst_money_account tmma
  1527. where tmma.flg_valid
  1528. and tmma.cp_id = #{cpId}
  1529. <if test="macCode !=null and macCode !=''">
  1530. AND tmma.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1531. </if>
  1532. <if test="macName !=null and macName !=''">
  1533. AND tmma.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1534. </if>
  1535. </select>
  1536. <!-- 查询表core.t_m_organization,查询业务部门多业务归属 -->
  1537. <select id="selectMultiOrg" resultType="java.util.Map">
  1538. select t.org_id as "orgId",
  1539. t.org_code as "orgCode",
  1540. t.org_name as "orgName",
  1541. case when mo.allocation_ratio is null then 100 else mo.allocation_ratio end as "allocationRatio",
  1542. case when mo.multi_id is null then 0 else 1 end as "selectFlag",
  1543. case when mo.owner_type = '归属类型-主部门' then true else false end as "ownerFlag"
  1544. from dkic_b.t_mst_org t
  1545. left join (SELECT tpmo.owner_id, tpmo.allocation_ratio, tpmo.multi_id, tpmo.owner_type
  1546. from dkic_b.t_psi_order tpo
  1547. inner join dkic_b.t_psi_multi_owner tpmo
  1548. on tpo.order_id = tpmo.order_id
  1549. where tpmo.flg_valid
  1550. and tpmo.owner_type = any (array ['归属类型-主部门' , '归属类型-从部门'])
  1551. and tpo.order_id = #{orderId} ::uuid) mo
  1552. on mo.owner_id = t.org_id
  1553. where t.flg_valid
  1554. <if test="orgCode !=null and orgCode !=''">
  1555. AND t.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1556. </if>
  1557. <if test="orgName !=null and orgName !=''">
  1558. AND t.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1559. </if>
  1560. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1561. limit #{end} offset #{start}
  1562. </if>
  1563. </select>
  1564. <!-- 查询表core.t_m_user,查询员工多业务归属 -->
  1565. <select id="selectMultiStaff" resultType="java.util.Map">
  1566. select t.staff_id as "staffId",
  1567. t.staff_code as "staffCode",
  1568. t.staff_name as "staffName",
  1569. tmo.org_name as "orgName",
  1570. case when mo.allocation_ratio is null then 100 else mo.allocation_ratio end as "allocationRatio",
  1571. case when mo.multi_id is null then 0 else 1 end as "selectFlag",
  1572. case when mo.owner_type = '归属类型-主员工' then true else false end as "ownerFlag"
  1573. from dkic_b.t_mst_staff t
  1574. left join dkic_b.t_mst_org as tmo on tmo.org_id = t.org_id
  1575. left join (SELECT tpmo.owner_id, tpmo.allocation_ratio, tpmo.multi_id, tpmo.owner_type
  1576. from dkic_b.t_psi_order tpo
  1577. inner join dkic_b.t_psi_multi_owner tpmo
  1578. on tpo.order_id = tpmo.order_id
  1579. where tpmo.flg_valid
  1580. and tpmo.owner_type = any (array ['归属类型-主员工' , '归属类型-从员工'])
  1581. and tpo.order_id = #{orderId} ::uuid
  1582. ) mo
  1583. on mo.owner_id = t.staff_id
  1584. where t.flg_valid
  1585. and t.flg_ghost = false
  1586. <if test="staffCode!=null and staffCode!='' ">
  1587. and t.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
  1588. </if>
  1589. <if test="staffName!=null and staffName!='' ">
  1590. and t.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  1591. </if>
  1592. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1593. limit #{end} offset #{start}
  1594. </if>
  1595. </select>
  1596. <!-- 查询表core.t_m_org_wh,查询组织仓库 -->
  1597. <select id="selectMultiWarehouse" resultType="java.util.Map">
  1598. select t.wh_id as "whId",
  1599. t.wh_code as "whCode",
  1600. t.wh_name as "whName",
  1601. case when mo.wh_id is null then 0 else 1 end as "selectFlag",
  1602. case when mo.wh_id is null then false else mo.flg_default end as "ownerFlag"
  1603. from dkic_b.t_mst_warehouse t
  1604. left join (SELECT orgwh.flg_default, orgwh.wh_id
  1605. from dkic_b.t_mst_org org
  1606. inner join dkic_b.t_mst_org_wh orgwh
  1607. on org.org_id = orgwh.org_id
  1608. where org.flg_valid
  1609. and org.org_id = #{orgId} ::uuid) mo
  1610. on mo.wh_id = t.wh_id
  1611. where t.flg_valid
  1612. <if test="whCode !=null and whCode !=''">
  1613. AND t.wh_code LIKE concat('%',my_ex.likequery(#{whCode}),'%')
  1614. </if>
  1615. <if test="whName !=null and whName !=''">
  1616. AND t.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1617. </if>
  1618. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1619. limit #{end} offset #{start}
  1620. </if>
  1621. </select>
  1622. <!-- 查询表core.t_m_org_mac,查询组织资金账户 -->
  1623. <select id="selectMultiMoneyAccount" resultType="java.util.Map">
  1624. select t.mac_id as "macId",
  1625. t.mac_code as "macCode",
  1626. t.mac_name as "macName",
  1627. case when mo.mac_id is null then 0 else 1 end as "selectFlag",
  1628. case when mo.mac_id is null then false else mo.flg_default end as "ownerFlag"
  1629. from dkic_b.t_mst_money_account t
  1630. left join (SELECT orgmac.flg_default,orgmac.mac_id
  1631. from dkic_b.t_mst_org org
  1632. inner join dkic_b.t_mst_org_mac orgmac
  1633. on org.org_id = orgmac.org_id
  1634. where org.flg_valid
  1635. and org.org_id = #{orgId} ::uuid) mo
  1636. on mo.mac_id = t.mac_id
  1637. where t.flg_valid
  1638. <if test="macCode !=null and macCode !=''">
  1639. AND t.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1640. </if>
  1641. <if test="macName !=null and macName !=''">
  1642. AND t.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1643. </if>
  1644. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1645. limit #{end} offset #{start}
  1646. </if>
  1647. </select>
  1648. <!-- 查询库存 -->
  1649. <select id="getGoodsForPurchaseReturn" resultType="java.util.Map">
  1650. select tpi.inv_id as "invId",
  1651. tpi.sku_id as "skuId",
  1652. tmgs.sku_code as "skuCode",
  1653. tmgs.sku_name as "skuName",
  1654. tmgs.sku_model as "skuModel",
  1655. tmgs.brand_id as "brandId",
  1656. tmgb.brand_name as "brandName",
  1657. tmgs.category_id as "categoryId",
  1658. tmgc.cat_name as "categoryName",
  1659. tmgs.unit_id as "unitId",
  1660. tmgu.unit_name as "unitName",
  1661. tmgs.sub_unit_id as "subUnitId",
  1662. tmgs.conversion_factor as "conversionFactor",
  1663. tmgs.series_id as "seriesId",
  1664. tmgseries.series_name as "seriesName",
  1665. tmgs.sku_spec as "skuSpec",
  1666. tmgs.price_purchase as "pricePurchase",
  1667. tmgs.price_standard as "priceStandard",
  1668. tmgs.price_wholesale as "priceWholesale",
  1669. tmgs.price_limited as "priceLimited",
  1670. tmgs.sku_images as "skuImages",
  1671. tpi.non_std_code as "nonStdCode",
  1672. tpi.inv_qty as "invQty",
  1673. tpi.outing_qty as "outingQty",
  1674. tpi.usable_qty as "usableQty",
  1675. tpi.wh_id as "whId",
  1676. tmw.wh_code as "whCode",
  1677. tmw.wh_name as "whName",
  1678. tpi.cost_price as "costPrice",
  1679. tpi.cost_amt as "costAmt",
  1680. tpi.remarks
  1681. from dkic_b.t_psi_inventory as tpi
  1682. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1683. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  1684. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  1685. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  1686. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  1687. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  1688. where tpi.flg_valid
  1689. AND tpi.cp_id = #{cpId}
  1690. <if test="skuId != null">
  1691. AND tpi.sku_id = #{skuId} ::uuid
  1692. </if>
  1693. <if test="nonStdCode != null">
  1694. AND tpi.non_std_code = #{nonStdCode}
  1695. </if>
  1696. <if test="skuCode != null">
  1697. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1698. </if>
  1699. <if test="skuName != null">
  1700. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1701. </if>
  1702. <if test="whName != null">
  1703. AND tmgs.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1704. </if>
  1705. <if test="whId != null">
  1706. AND tpi.wh_id = #{whId} ::uuid
  1707. </if>
  1708. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1709. limit #{end} offset #{start}
  1710. </if>
  1711. </select>
  1712. <!-- 查询库存个数 -->
  1713. <select id="getGoodsForPurchaseReturnByPage" resultType="Long">
  1714. SELECT
  1715. count(1)
  1716. from dkic_b.t_psi_inventory as tpi
  1717. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1718. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  1719. where tpi.flg_valid
  1720. AND tpi.cp_id = #{cpId}
  1721. <if test="skuId != null">
  1722. AND tpi.sku_id = #{skuId} ::uuid
  1723. </if>
  1724. <if test="nonStdCode != null">
  1725. AND tpi.non_std_code = #{nonStdCode}
  1726. </if>
  1727. <if test="skuCode != null">
  1728. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1729. </if>
  1730. <if test="skuName != null">
  1731. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1732. </if>
  1733. <if test="whName != null">
  1734. AND tmgs.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1735. </if>
  1736. </select>
  1737. <!--范围权限类型-->
  1738. <select id="getPurviewType" resultType="java.util.Map">
  1739. select tpt.purview_name_i18n as purviewName,
  1740. tpt.purview_code as "code",
  1741. "row_number"() OVER (ORDER BY tpt.display_no) as "id",
  1742. sys.f_get_name_i18n(tpt.purview_name_i18n, #{i18n}) AS name
  1743. from sys.t_purview_type tpt
  1744. where tpt.flg_valid
  1745. order by tpt.display_no
  1746. </select>
  1747. <select id="getInventoryByList" resultType="java.util.Map">
  1748. select tpi.inv_id as "invId",
  1749. tpi.sku_id as "skuId",
  1750. tpi.non_std_code as "nonStdCode",
  1751. tpi.inv_qty as "invQty",
  1752. tpi.outing_qty as "outingQty",
  1753. tpi.usable_qty as "usableQty",
  1754. tpi.wh_id as "whId",
  1755. tmw.wh_name as "whName",
  1756. tpi.remarks
  1757. from dkic_b.t_psi_inventory as tpi
  1758. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1759. <where>
  1760. <foreach collection="skuIdNonStdCodeWhIdList" item="condition" separator=" OR ">
  1761. <if test="condition.skuId != null">
  1762. tpi.sku_id = #{condition.skuId} ::uuid
  1763. </if>
  1764. <if test="condition.nonStdCode != null">
  1765. AND tpi.non_std_code = #{condition.nonStdCode}
  1766. </if>
  1767. <if test="condition.whId != null">
  1768. AND tpi.wh_id = #{condition.whId} ::uuid
  1769. </if>
  1770. AND tpi.flg_valid
  1771. AND tpi.cp_id = #{cpId}
  1772. </foreach>
  1773. </where>
  1774. </select>
  1775. <!-- 查询标签打印项目 -->
  1776. <select id="getLabelPrintItem" resultType="java.util.Map">
  1777. select
  1778. item_code as "itemCode",
  1779. sys.f_get_name_i18n(item_name_i18n,#{i18n}) as "itemName",
  1780. doc_name as "docName",
  1781. item_type as "itemType",
  1782. item_style as "itemStyle",
  1783. item_sample as "itemSample",
  1784. data_key as "dataKey",
  1785. remarks as "remarks"
  1786. from sys.t_label_print_item
  1787. where flg_valid
  1788. <if test="docName">
  1789. and doc_name = #{docName}
  1790. </if>
  1791. order by display_no
  1792. </select>
  1793. <!--获取组织仓库-->
  1794. <select id="getOrgWh" resultType="java.util.Map">
  1795. select t.wh_id as "whId",
  1796. tmw.wh_name as "whName",
  1797. t.flg_default as "flgDefault"
  1798. from dkic_b.t_mst_org_wh t
  1799. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
  1800. where t.cp_id = #{cpId}
  1801. and t.org_id = #{orgId}::uuid
  1802. order by t.display_no
  1803. </select>
  1804. <!-- 获取商品(其他入库开单用) -->
  1805. <select id="getGoodsForInto" resultType="java.util.Map">
  1806. select tmgs.sku_id as "skuId",
  1807. tmgs.sku_code as "skuCode",
  1808. tmgs.sku_name as "skuName",
  1809. tmgs.sku_model as "skuModel",
  1810. tmgs.brand_id as "brandId",
  1811. tmgb.brand_name as "brandName",
  1812. tmgs.category_id as "categoryId",
  1813. tmgc.cat_name as "categoryName",
  1814. tmgs.conversion_factor as "conversionFactor",
  1815. tmgs.series_id as "seriesId",
  1816. tmgseries.series_name as "seriesName",
  1817. tmgs.sku_spec as "skuSpec",
  1818. tmgs.price_purchase as "priceInto",
  1819. tmgs.price_standard as "priceStandard",
  1820. tmgs.price_wholesale as "priceWholesale",
  1821. tmgs.price_limited as "priceLimited",
  1822. tmgs.sku_images as "skuImages",
  1823. tmgs.pack_box as "packBox",
  1824. tmgs.unit_id as "unitId",
  1825. tmgs.sub_unit_id as "subUnitId",
  1826. ul.unit_name as "unitName",
  1827. u2.unit_name as "subUnitName",
  1828. tmgs.remarks
  1829. from dkic_b.t_mst_goods_sku as tmgs
  1830. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  1831. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  1832. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  1833. left join dkic_b.t_mst_unit as ul on tmgs.unit_id = ul.unit_id
  1834. left join dkic_b.t_mst_unit as u2 on tmgs.sub_unit_id = u2.unit_id
  1835. where tmgs.flg_valid
  1836. AND tmgs.cp_id = #{cpId}
  1837. <if test="skuCode != null">
  1838. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1839. </if>
  1840. <if test="skuName != null">
  1841. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1842. </if>
  1843. <if test="categoryId != null">
  1844. AND tmgs.category_id = #{categoryId}::uuid
  1845. </if>
  1846. </select>
  1847. <!-- 获取商品(其他入库开单用)(数量) -->
  1848. <select id="getGoodsForIntoCountByPage" resultType="Long">
  1849. SELECT
  1850. count(1)
  1851. from dkic_b.t_mst_goods_sku as tmgs
  1852. where tmgs.flg_valid
  1853. AND tmgs.cp_id = #{cpId}
  1854. <if test="skuCode != null">
  1855. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1856. </if>
  1857. <if test="skuName != null">
  1858. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1859. </if>
  1860. </select>
  1861. <select id="selectDictionaryData" resultType="java.util.Map">
  1862. select dd.data_id as "dataId",
  1863. dd.data_id as "id",
  1864. dd.dict_code as "dictCode",
  1865. dd.data_code as "dataCode",
  1866. dd.data_value as "dataValue",
  1867. dd.flg_default as "flgDefault"
  1868. from dkic_b.t_mst_dictionary_data as dd
  1869. where dd.flg_valid
  1870. and dd.cp_id = #{cpId}
  1871. and dd.dict_code = #{dictCode}
  1872. and dd.data_value = #{dataValue}
  1873. </select>
  1874. <!-- 销售分析-我的 门店助手的 销售金额 收款金额 库存成本 -->
  1875. <select id="getHomeOrderRecCost" resultType="java.util.Map">
  1876. select dkic_b.f_get_home_order_rec_cost(#{cpId},#{dateBegin}::date,#{dateEnd}::date,#{staffId}::uuid)
  1877. </select>
  1878. <!--查询用户授权数-->
  1879. <select id="selectUserCount" resultType="java.util.Map">
  1880. SELECT
  1881. (
  1882. SELECT COUNT
  1883. ( 1 ) "webNum"
  1884. FROM
  1885. dkic_b.t_mst_staff s
  1886. WHERE
  1887. s.flg_valid
  1888. AND s.flg_can_login
  1889. AND s.login_type IN ( 1, 3 )
  1890. AND s.hr_status = 1
  1891. AND s.cp_id = #{cpId}
  1892. ),
  1893. (
  1894. SELECT COUNT
  1895. ( 1 ) "wxNum"
  1896. FROM
  1897. dkic_b.t_mst_staff s
  1898. WHERE
  1899. s.flg_valid
  1900. AND s.flg_can_login
  1901. AND s.hr_status = 1
  1902. AND s.login_type IN ( 2, 3 )
  1903. AND s.cp_id = #{cpId}
  1904. ),
  1905. CURRENT_DATE as "currentDate"
  1906. </select>
  1907. <!--查询公司-->
  1908. <select id="getCompany" resultType="java.util.Map">
  1909. select t.cp_id as "cpId",
  1910. t.cp_code as "cpCode",
  1911. t.cp_name as "cpName",
  1912. t.svc_code as "svcCode",
  1913. t.opening_date as "openingDate",
  1914. t.grade_code as "gradeCode",
  1915. t.end_date as "endDate",
  1916. t.max_staff_num as "maxStaffNum",
  1917. t.flg_valid as "flgValid",
  1918. t.remarks,
  1919. t.owner
  1920. from dkic_a.t_a_company as t
  1921. where t.cp_id = #{cpId}
  1922. </select>
  1923. <!--查询首页实时数据1-->
  1924. <select id="getRealTimeData1" resultType="java.util.Map">
  1925. select count(1) as "orderQty", coalesce(sum(t.sum_amount), 0) as "orderAmt"
  1926. from dkic_b.t_psi_order as t
  1927. where t.flg_valid
  1928. and t.cp_id = #{cpId}
  1929. and t.op_create_time <![CDATA[ >= ]]> #{createTimeStart}
  1930. and t.op_create_time <![CDATA[ < ]]> #{createTimeEnd}
  1931. </select>
  1932. <!--查询首页实时数据2-->
  1933. <select id="getRealTimeData2" resultType="java.util.Map">
  1934. select count(1) as "outQty", coalesce(sum(t.out_amt), 0) as "outAmt"
  1935. from dkic_b.t_psi_outbound as t
  1936. where t.flg_valid
  1937. and t.out_type = '出库类型-销售出库'
  1938. and t.cp_id = #{cpId}
  1939. and t.op_create_time <![CDATA[ >= ]]> #{createTimeStart}
  1940. and t.op_create_time <![CDATA[ < ]]> #{createTimeEnd}
  1941. </select>
  1942. <!--查询首页实时数据3-->
  1943. <select id="getRealTimeData3" resultType="java.util.Map">
  1944. select count(1) as "returnQty", -coalesce(sum(t.out_amt), 0) as "returnAmt"
  1945. from dkic_b.t_psi_outbound as t
  1946. where t.flg_valid
  1947. and t.out_type = '出库类型-销退回库'
  1948. and t.cp_id = #{cpId}
  1949. and t.op_create_time <![CDATA[ >= ]]> #{createTimeStart}
  1950. and t.op_create_time <![CDATA[ < ]]> #{createTimeEnd}
  1951. </select>
  1952. <!--查询首页实时数据4-->
  1953. <select id="getRealTimeData4" resultType="java.util.Map">
  1954. select count(1) as "cusQty", coalesce(sum(t.sum_amount), 0) as "cusAmt"
  1955. from (select sum(t.sum_amount) as sum_amount
  1956. from dkic_b.t_psi_order as t
  1957. where t.flg_valid
  1958. and t.cp_id = #{cpId}
  1959. and t.op_create_time <![CDATA[ >= ]]> #{createTimeStart}
  1960. and t.op_create_time <![CDATA[ < ]]> #{createTimeEnd}
  1961. group by t.cus_id) as t
  1962. </select>
  1963. </mapper>