CommonMapper.xml 76 KB

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