CommonMapper.xml 78 KB

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