CommonMapper.xml 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  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. tmgs.sub_unit_id as "subUnitId",
  527. tmgs.conversion_factor as "conversionFactor",
  528. tmgs.series_id as "seriesId",
  529. tmgseries.series_name as "seriesName",
  530. tmgs.sku_spec as "skuSpec",
  531. tmgs.price_purchase as "pricePurchase",
  532. tmgs.price_standard as "priceStandard",
  533. tmgs.price_wholesale as "priceWholesale",
  534. tmgs.price_limited as "priceLimited",
  535. tmgs.sku_images as "skuImages",
  536. tmgs.pack_box as "packBox",
  537. tmgs.remarks
  538. from dkic_b.t_mst_goods_sku as tmgs
  539. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  540. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  541. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  542. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  543. where tmgs.flg_valid
  544. AND tmgs.cp_id = #{cpId}
  545. <if test="skuCode != null">
  546. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  547. </if>
  548. <if test="skuName != null">
  549. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  550. </if>
  551. </select>
  552. <!-- 获取商品个数(采购) -->
  553. <select id="getGoodsForPurchaseCountByPage" resultType="Long">
  554. SELECT
  555. count(1)
  556. from dkic_b.t_mst_goods_sku as tmgs
  557. where tmgs.flg_valid
  558. AND tmgs.cp_id = #{cpId}
  559. <if test="skuCode != null">
  560. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  561. </if>
  562. <if test="skuName != null">
  563. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  564. </if>
  565. </select>
  566. <!-- 获取客户 -->
  567. <select id="getCustomer" resultType="java.util.Map">
  568. select tmc.cus_id as "cusId",
  569. tmc.cus_code as "cusCode",
  570. tmc.cus_name as "cusName",
  571. tmc.cus_phone as "cusPhone",
  572. tmc.address_area as "addressArea",
  573. tmc.address_name as "addressName",
  574. tmc.address_no as "addressNo",
  575. tmc.address_gcj02 as "addressGcj02",
  576. tmc.address_full as "addressFull",
  577. tmc.contact_name as "contactName",
  578. tmc.contact_phone as "contactPhone",
  579. tmc.cus_from as "cusFrom",
  580. tmdd.data_value as "cusFromName",
  581. tmc.channel_id as "channelId",
  582. tmsc.channel_name as "channelName",
  583. tmc.org_id as "orgId",
  584. tmo.org_name as "orgName",
  585. tmc.staff_id as "staffId",
  586. tms.staff_name as "staffName",
  587. tmc.report_staff as "reportStaff",
  588. reportstaff.staff_name as "reportStaffName",
  589. tmc.report_time as "reportTime",
  590. tmc.sale_status as "saleStatus",
  591. tmc.remarks as "remarks",
  592. tmc.follow_staffs as "followStaffs",
  593. tmc.last_follow_staff as "lastFollowStaff",
  594. tmc.last_follow_id as "lastFollowId",
  595. tmc.last_follow_status as "lastFollowStatus",
  596. tmc.last_follow_time as "lastFollowTime"
  597. from dkic_b.t_mst_customer as tmc
  598. left join dkic_b.t_mst_org tmo on tmc.org_id = tmo.org_id
  599. left join dkic_b.t_mst_staff tms on tmc.staff_id = tms.staff_id
  600. left join dkic_b.t_mst_staff as reportstaff on tmc.report_staff = reportstaff.staff_id
  601. left join dkic_b.t_mst_sale_channel tmsc on tmc.channel_id = tmsc.channel_id
  602. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  603. where tmc.flg_valid
  604. AND tmc.cp_id = #{cpId}
  605. <if test="skuCode != null">
  606. AND tmc.cus_code = #{cusCode}
  607. </if>
  608. <if test="skuName != null">
  609. AND tmc.cus_name = #{cusName}
  610. </if>
  611. </select>
  612. <!-- 获取客户个数 -->
  613. <select id="getCustomerCountByPage" resultType="Long">
  614. SELECT
  615. count(1)
  616. from dkic_b.t_mst_customer as tmc
  617. where tmc.flg_valid
  618. and tmc.cp_id = #{cpId}
  619. <if test="skuCode != null">
  620. AND tmc.cus_code = #{cusCode}
  621. </if>
  622. <if test="skuName != null">
  623. AND tmc.cus_name = #{cusName}
  624. </if>
  625. </select>
  626. <!-- 获取单据Id-->
  627. <select id="getUuidSeq" resultType="object">
  628. select sys.f_uuid_seq()
  629. </select>
  630. <!-- 获取单据单号-->
  631. <select id="getDocNo" resultType="java.lang.String">
  632. select dkic_b.f_create_note(#{cpId}, #{purId}::uuid, #{docCode})
  633. </select>
  634. <!--获取供应商-->
  635. <select id="getSupplier" resultType="java.util.Map">
  636. select tms.sup_code as "supplierCode",
  637. tms.sup_name as "supplierName",
  638. tms.sup_id as "supplierId",
  639. sys.f_get_name_i18n(tdk.kind_name_i18n, #{i18n}) AS "supplierType",
  640. tms.contact_name as "contactName",
  641. tms.contact_phone as "contactPhone",
  642. tms.flg_valid as "flgValid"
  643. from dkic_b.t_mst_supplier tms
  644. LEFT JOIN sys.t_data_kind tdk
  645. ON tdk.kind_code = tms.sup_type
  646. where tms.cp_id = #{cpId}
  647. <if test="supplierName!=null and supplierName!=''">
  648. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{supplierName}),'%')
  649. </if>
  650. <if test="supplierCode!=null and supplierCode!=''">
  651. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{supplierCode}),'%')
  652. </if>
  653. <if test="supplierType!=null and supplierType!=''">
  654. AND tms.sup_type = #{supplierType}
  655. </if>
  656. order by tms.sup_code
  657. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  658. limit #{end} offset #{start}
  659. </if>
  660. <if test="limit != null and limit != 0 ">
  661. limit #{limit}
  662. </if>
  663. </select>
  664. <!--获取供应商数量-->
  665. <select id="countSupplier" resultType="java.lang.Long">
  666. select count(1)
  667. from dkic_b.t_mst_supplier tms
  668. LEFT JOIN sys.t_data_kind tdk
  669. ON tdk.kind_code = tms.sup_type
  670. where tms.cp_id = #{cpId}
  671. <if test="supplierName!=null and supplierName!=''">
  672. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{supplierName}),'%')
  673. </if>
  674. <if test="supplierCode!=null and supplierCode!=''">
  675. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{supplierCode}),'%')
  676. </if>
  677. <if test="supplierType!=null and supplierType!=''">
  678. AND tms.sup_type LIKE concat('%',my_ex.likequery(#{supplierType}),'%')
  679. </if>
  680. </select>
  681. <!--获取渠道 -->
  682. <select id="getChannel" resultType="java.util.Map">
  683. select c.channel_id as "channelId",
  684. c.channel_code as "channelCode",
  685. c.channel_name as "channelName",
  686. c.sys_code as "sysCode",
  687. c.display_no as "displayNo"
  688. from dkic_b.t_mst_sale_channel as c
  689. where c.flg_valid
  690. and c.cp_id = #{cpId}
  691. <if test="channel_code!=null and channel_code!=''">
  692. AND c.channel_code LIKE concat('%', #{channelCode}, '%')
  693. </if>
  694. <if test="channel_name!=null and channel_name!=''">
  695. AND c.channel_name LIKE concat('%', #{channelName}, '%')
  696. </if>
  697. order by c.display_no
  698. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  699. limit #{end} offset #{start}
  700. </if>
  701. <if test="limit != null and limit != 0 ">
  702. limit #{limit}
  703. </if>
  704. </select>
  705. <!-- 查询商品档案-->
  706. <select id="getGoodsBrand" resultType="java.util.Map">
  707. SELECT
  708. tmgb.flg_valid AS "flgValid",
  709. tmgb.brand_id AS "brandId", tmgb.brand_code AS "brandCode", tmgb.brand_name AS "brandName",
  710. (SELECT COALESCE(array_to_string(array_agg(tsm.sup_name), ','),'')
  711. FROM dkic_b.t_mst_supplier_brand tsmb
  712. left join dkic_b.t_mst_supplier tsm on tsm.sup_id = tsmb.sup_id
  713. WHERE tsmb.brand_id = tmgb.brand_id) AS "supplierName"
  714. FROM dkic_b.t_mst_goods_brand tmgb
  715. <where>
  716. <if test="searchText !=null">
  717. AND tmgb.brand_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  718. </if>
  719. <if test="cpId != null">
  720. AND tmgb.cp_id = #{cpId}
  721. </if>
  722. <if test="flgValid != null">
  723. AND tmgb.flg_valid = #{flgValid}
  724. </if>
  725. </where>
  726. order by tmgb.display_no asc
  727. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  728. limit #{end} offset #{start}
  729. </if>
  730. </select>
  731. <!-- 查询商品种类-->
  732. <select id="getGoodsCategoryTree" resultType="java.util.Map">
  733. SELECT
  734. T.cat_id AS "catId",
  735. T.cat_code AS "catCode",
  736. T.cat_name AS "catName",
  737. T.parent_id AS "parentId",
  738. T.flg_valid AS "flgValid"
  739. FROM
  740. (--当前数据
  741. SELECT
  742. tmgc.cat_id,
  743. tmgc.cat_code,
  744. tmgc.cat_name,
  745. tmgc.parent_id,
  746. tmgc.flg_valid
  747. FROM
  748. dkic_b.t_mst_goods_category tmgc
  749. <where>
  750. <if test="searchText !=null">
  751. AND ( tmgc.cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  752. or tmgc.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  753. </if>
  754. <if test="cpId != null">
  755. AND tmgc.cp_id = #{cpId}
  756. </if>
  757. </where>
  758. UNION ALL--父级
  759. SELECT
  760. tmgcp.cat_id,
  761. tmgcp.cat_code,
  762. tmgcp.cat_name,
  763. tmgcp.parent_id,
  764. tmgcp.flg_valid
  765. FROM
  766. dkic_b.t_mst_goods_category tmgc
  767. LEFT JOIN dkic_b.t_mst_goods_category tmgcp ON tmgc.cat_id = ANY ( tmgcp.level_lower )
  768. <where>
  769. <if test="searchText !=null">
  770. AND ( tmgc.cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  771. or tmgc.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  772. </if>
  773. <if test="cpId != null">
  774. AND tmgc.cp_id = #{cpId}
  775. </if>
  776. </where>
  777. ) T
  778. WHERE T.cat_id IS NOT NULL
  779. GROUP BY
  780. T.cat_id,
  781. T.cat_code,
  782. T.cat_name,
  783. T.parent_id,
  784. T.flg_valid
  785. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  786. limit #{end} offset #{start}
  787. </if>
  788. </select>
  789. <!-- 查询表t_mst_goods_brand,(条件查询)个数 -->
  790. <select id="countGoodsBrand" resultType="Long">
  791. SELECT
  792. count(1)
  793. FROM dkic_b.t_mst_goods_brand tmgb
  794. <where>
  795. <if test="searchText !=null">
  796. AND tmgb.brand_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  797. </if>
  798. <if test="cpId != null">
  799. AND tmgb.cp_id = #{cpId}
  800. </if>
  801. <if test="flgValid != null">
  802. AND tmgb.flg_valid = #{flgValid}
  803. </if>
  804. </where>
  805. </select>
  806. <!-- 查询商品种类-->
  807. <select id="getGoodsCategory" resultType="java.util.Map">
  808. SELECT
  809. cat_id AS "catId",
  810. cat_code AS "catCode",
  811. cat_name AS "catName",
  812. parent_id AS "parentId",
  813. flg_valid AS "flgValid"
  814. FROM dkic_b.t_mst_goods_category
  815. <where>
  816. <if test="searchText !=null">
  817. AND ( cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  818. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  819. </if>
  820. <if test="cpId != null">
  821. AND cp_id = #{cpId}
  822. </if>
  823. </where>
  824. ORDER BY display_no
  825. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  826. limit #{end} offset #{start}
  827. </if>
  828. </select>
  829. <!-- 查询商品种类的个数-->
  830. <select id="countGoodsCategory" resultType="java.lang.Long">
  831. SELECT
  832. count(1)
  833. FROM dkic_b.t_mst_goods_category
  834. <where>
  835. <if test="searchText !=null">
  836. AND ( cat_name LIKE concat('%', #{searchText}, '%')
  837. or remarks LIKE concat('%', #{searchText}, '%'))
  838. </if>
  839. <if test="cpId != null">
  840. AND cp_id = #{cpId}
  841. </if>
  842. </where>
  843. </select>
  844. <!-- 查询商品系列-->
  845. <select id="getGoodsSeries" resultType="java.util.Map">
  846. SELECT
  847. series_id AS "seriesId",
  848. series_code AS "seriesCode",
  849. series_name AS "serieName",
  850. flg_valid AS "flgValid"
  851. FROM dkic_b.t_mst_goods_series
  852. <where>
  853. <if test="searchText !=null">
  854. AND ( series_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  855. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  856. </if>
  857. <if test="cpId != null">
  858. AND cp_id = #{cpId}
  859. </if>
  860. </where>
  861. order by display_no asc
  862. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  863. limit #{end} offset #{start}
  864. </if>
  865. </select>
  866. <!-- 商品系列个数-->
  867. <select id="countGoodsSeries" resultType="java.lang.Long">
  868. SELECT
  869. count(1)
  870. FROM dkic_b.t_mst_goods_series
  871. <where>
  872. <if test="searchText !=null">
  873. AND ( series_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  874. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  875. </if>
  876. <if test="cpId != null">
  877. AND cp_id = #{cpId}
  878. </if>
  879. </where>
  880. </select>
  881. <!-- 获取计量单位-->
  882. <select id="getUnit" resultType="java.util.Map">
  883. SELECT
  884. unit_id AS "unitId",
  885. unit_code AS "unitCode",
  886. unit_name AS "unitName",
  887. decimal_places AS "decimalPlaces",
  888. flg_valid AS "flgValid"
  889. FROM dkic_b.t_mst_unit
  890. <where>
  891. <if test="searchText !=null">
  892. AND ( unit_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  893. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  894. </if>
  895. <if test="cpId != null">
  896. AND cp_id = #{cpId}
  897. </if>
  898. </where>
  899. order by display_no asc
  900. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  901. limit #{end} offset #{start}
  902. </if>
  903. </select>
  904. <!-- 获取计量单位个数-->
  905. <select id="countUnit" resultType="java.lang.Long">
  906. SELECT
  907. count(1)
  908. FROM dkic_b.t_mst_unit
  909. <where>
  910. <if test="searchText !=null">
  911. AND ( unit_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  912. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  913. </if>
  914. <if test="cpId != null">
  915. AND cp_id = #{cpId}
  916. </if>
  917. </where>
  918. </select>
  919. <!--获取仓库档案-->
  920. <select id="getWarehouseByPage" resultType="java.util.Map">
  921. SELECT t.wh_id AS "whId",
  922. t.wh_code AS "whCode",
  923. t.wh_name AS "whName",
  924. t.supervisor AS "supervisor",
  925. t.contact_phone AS "contactPhone",
  926. t.flg_valid AS "flgValid"
  927. FROM dkic_b.t_mst_warehouse as t
  928. <where>
  929. <if test="searchText !=null">
  930. AND ( t.wh_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  931. or t.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  932. </if>
  933. <if test="cpId != null">
  934. AND t.cp_id = #{cpId}
  935. </if>
  936. <if test="flgValid != null">
  937. AND t.flg_valid = #{flgValid}
  938. </if>
  939. <!-- 部门上有仓库,只能选部门上的仓库;部门上没有仓库,可选所有仓库 -->
  940. <if test="orgId != null">
  941. and (select count(1)
  942. from dkic_b.t_mst_org_wh as tmow
  943. where tmow.org_id = #{orgId}::uuid) = 0
  944. or (exists(select 1
  945. from dkic_b.t_mst_org_wh as tmow
  946. where tmow.org_id = #{orgId}::uuid
  947. and tmow.wh_id = t.wh_id))
  948. </if>
  949. </where>
  950. order by display_no asc
  951. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  952. limit #{end} offset #{start}
  953. </if>
  954. </select>
  955. <!--获取仓库档案个数-->
  956. <select id="countWarehouseByPage" resultType="Long">
  957. SELECT count(1)
  958. FROM dkic_b.t_mst_warehouse as t
  959. <where>
  960. <if test="searchText !=null">
  961. AND ( t.wh_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  962. or t.remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  963. </if>
  964. <if test="cpId != null">
  965. AND t.cp_id = #{cpId}
  966. </if>
  967. <!-- 部门上有仓库,只能选部门上的仓库;部门上没有仓库,可选所有仓库 -->
  968. <if test="orgId != null">
  969. and (select count(1)
  970. from dkic_b.t_mst_org_wh as tmow
  971. where tmow.org_id = #{orgId}::uuid) = 0
  972. or (exists(select 1
  973. from dkic_b.t_mst_org_wh as tmow
  974. where tmow.org_id = #{orgId}::uuid
  975. and tmow.wh_id = t.wh_id))
  976. </if>
  977. </where>
  978. </select>
  979. <!-- 查询库存 -->
  980. <select id="getInventory" resultType="java.util.Map">
  981. select tpi.inv_id as "invId",
  982. tpi.sku_id as "skuId",
  983. tmgs.sku_code as "skuCode",
  984. tmgs.sku_name as "skuName",
  985. tmgs.sku_model as "skuModel",
  986. tmgs.brand_id as "brandId",
  987. tmgb.brand_name as "brandName",
  988. tmgs.category_id as "categoryId",
  989. tmgc.cat_name as "categoryName",
  990. tmgs.unit_id as "unitId",
  991. tmgu.unit_name as "unitName",
  992. tmgs.sub_unit_id as "subUnitId",
  993. tmgs.conversion_factor as "conversionFactor",
  994. tmgs.series_id as "seriesId",
  995. tmgseries.series_name as "seriesName",
  996. tmgs.sku_spec as "skuSpec",
  997. tmgs.price_purchase as "pricePurchase",
  998. tmgs.price_standard as "priceStandard",
  999. tmgs.price_wholesale as "priceWholesale",
  1000. tmgs.price_limited as "priceLimited",
  1001. tmgs.sku_images as "skuImages",
  1002. tpi.non_std_code as "nonStdCode",
  1003. tpi.inv_qty as "invQty",
  1004. tpi.outing_qty as "outingQty",
  1005. tpi.freeze_qty as "freezeQty",
  1006. tpi.usable_qty as "usableQty",
  1007. tpi.wh_id as "whId",
  1008. tmw.wh_code as "whCode",
  1009. tmw.wh_name as "whName",
  1010. tmgs.pack_box as "packBox",
  1011. tmgs.unit_id as "unitId",
  1012. tmgs.sub_unit_id as "subUnitId",
  1013. dkic_b.f_get_last_ivt_price(tpi.inv_id,null,null,null) as "priceInto",
  1014. tpi.remarks
  1015. from dkic_b.t_psi_inventory as tpi
  1016. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1017. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  1018. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  1019. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  1020. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  1021. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  1022. where tpi.flg_valid
  1023. AND tpi.cp_id = #{cpId}
  1024. <if test="skuId != null">
  1025. AND tpi.sku_id = #{skuId} ::uuid
  1026. </if>
  1027. <if test="nonStdCode != null">
  1028. AND tpi.non_std_code = #{nonStdCode}
  1029. </if>
  1030. <if test="skuCode != null">
  1031. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1032. </if>
  1033. <if test="skuName != null">
  1034. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1035. </if>
  1036. <if test="whName != null">
  1037. AND tmw.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1038. </if>
  1039. <if test="whId != null">
  1040. AND tpi.wh_id = #{whId} ::uuid
  1041. </if>
  1042. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1043. limit #{end} offset #{start}
  1044. </if>
  1045. </select>
  1046. <!-- 查询库存个数 -->
  1047. <select id="getInventoryCountByPage" resultType="Long">
  1048. SELECT
  1049. count(1)
  1050. from dkic_b.t_psi_inventory as tpi
  1051. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1052. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_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 tmgs.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1069. </if>
  1070. </select>
  1071. <!-- 获取销售渠道-->
  1072. <select id="getSaleChannel" resultType="java.util.Map">
  1073. SELECT
  1074. channel_id AS "channelId",
  1075. channel_id AS "id",
  1076. channel_code AS "channelCode",
  1077. channel_name AS "channelName"
  1078. FROM dkic_b.t_mst_sale_channel
  1079. <where>
  1080. flg_valid
  1081. <if test="cpId != null">
  1082. AND cp_id = #{cpId}
  1083. </if>
  1084. order by display_no
  1085. </where>
  1086. </select>
  1087. <!--获取结算方式数据-->
  1088. <select id="getSettlement" resultType="java.util.Map">
  1089. SELECT T.mac_id id,
  1090. T.mac_code AS "macCode",
  1091. T.mac_name AS "macName",
  1092. T.mac_Type,
  1093. dd.data_value AS "macTypeName",
  1094. T.balance,
  1095. T.display_no,
  1096. T.mac_receipt_code,
  1097. T.acc_date,
  1098. T.flg_negative,
  1099. T.remarks,
  1100. T.flg_valid,
  1101. T.cp_id,
  1102. COALESCE ( tmti.amt_trf, 0 ) AS "initBalance"
  1103. FROM
  1104. dkic_b.t_mst_money_account
  1105. AS T LEFT JOIN dkic_b.t_mst_dictionary_data AS dd ON T.mac_type = dd.data_id
  1106. LEFT JOIN (
  1107. SELECT
  1108. tmti.trf_in_mac,
  1109. tmti.amt_trf
  1110. FROM
  1111. dkic_b.t_mac_transfer AS tmt
  1112. INNER JOIN dkic_b.t_mac_transfer_item AS tmti ON tmti.trf_id = tmt.trf_id
  1113. AND tmt.flg_valid
  1114. AND tmti.flg_valid
  1115. AND tmt.trf_type = 0
  1116. ) tmti ON tmti.trf_in_mac = T.mac_id
  1117. WHERE
  1118. T.cp_id = #{cpId}
  1119. and t.flg_valid
  1120. ORDER BY
  1121. T.display_no
  1122. </select>
  1123. <!-- 获取销售渠道-->
  1124. <select id="getSaleChannelPurviewType" resultType="java.util.Map">
  1125. SELECT
  1126. sc.channel_id AS "channelId",
  1127. sc.channel_id AS "id",
  1128. sc.channel_code AS "channelCode",
  1129. sc.channel_name AS "channelName",
  1130. COALESCE ( ( SELECT flg_nolimit FROM dkic_b.t_mst_staff_purview WHERE staff_id = #{staffId} :: UUID and purview_code = #{purviewCode}), FALSE ) "flgNolimit",
  1131. CASE WHEN scsc.channel_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
  1132. FROM dkic_b.t_mst_sale_channel sc
  1133. left JOIN dkic_b.t_mst_sale_channel scsc ON scsc.channel_id = sc.channel_id and sc.channel_id::uuid = any ( (
  1134. select data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid and purview_code = #{purviewCode})::uuid[])
  1135. <where>
  1136. sc.flg_valid
  1137. <if test="cpId != null">
  1138. AND sc.cp_id = #{cpId}
  1139. </if>
  1140. <if test="channelCode !=null and channelCode !=''">
  1141. AND sc.channel_code LIKE concat('%',my_ex.likequery(#{channelCode}),'%')
  1142. </if>
  1143. <if test="channelName !=null and channelName !=''">
  1144. AND sc.channel_name LIKE concat('%',my_ex.likequery(#{channelName}),'%')
  1145. </if>
  1146. order by sc.display_no
  1147. </where>
  1148. </select>
  1149. <!--获取仓库档案-->
  1150. <!--获取供应商和客户数据-->
  1151. <select id="getSupplierAndCustomer" resultType="java.util.Map">
  1152. select tms.sup_id as "objId",
  1153. tms.sup_code as "objCode",
  1154. tms.sup_name as "objName",
  1155. '供应商' as "objTypeName",
  1156. 1 as "objType",
  1157. tms.flg_valid as "flgValid"
  1158. null as "phone",
  1159. null as "addressFull"
  1160. from dkic_b.t_mst_supplier tms
  1161. <where>
  1162. <if test="flgValid">
  1163. AND tms.flg_valid
  1164. </if>
  1165. <if test="objCode != null and objCode != ''">
  1166. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1167. </if>
  1168. <if test="objName != null and objName != ''">
  1169. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1170. </if>
  1171. </where>
  1172. union all
  1173. select cus.cus_id as "objId",
  1174. cus.cus_code as "objCode",
  1175. cus.cus_name as "objName",
  1176. '客户' as "objTypeName",
  1177. 2 as "objType",
  1178. cus.flg_valid as "flgValid",
  1179. cus.cus_phone as "phone",
  1180. cus.address_full as "addressFull"
  1181. from dkic_b.t_mst_customer cus
  1182. <where>
  1183. <if test="flgValid">
  1184. AND cus.flg_valid
  1185. </if>
  1186. <if test="objCode != null and objCode != ''">
  1187. AND cus.cus_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1188. </if>
  1189. <if test="objName != null and objName != ''">
  1190. AND cus.cus_name LIKE concat('%',my_ex.likequery(#{objName}),'%')
  1191. </if>
  1192. </where>
  1193. </select>
  1194. <!--获取供应商和客户数据分页-->
  1195. <select id="getSupplierAndCustomerByPage" resultType="java.util.Map">
  1196. select * from (
  1197. select tms.sup_id as "objId",
  1198. tms.sup_code as "objCode",
  1199. tms.sup_name as "objName",
  1200. '供应商' as "objTypeName",
  1201. 1 as "objType",
  1202. tms.flg_valid as "flgValid",
  1203. tms.contact_phone as "phone",
  1204. tms.return_address as "addressFull"
  1205. from dkic_b.t_mst_supplier tms
  1206. <where >
  1207. tms.sup_type = '供应商类别-采购'
  1208. and tms.cp_id = #{cpId}
  1209. <if test="flgValid">
  1210. AND tms.flg_valid
  1211. </if>
  1212. <if test="objCode != null and objCode != ''">
  1213. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1214. </if>
  1215. <if test="objName != null and objName != ''">
  1216. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1217. </if>
  1218. <if test="searchText != null and searchText != ''">
  1219. AND (
  1220. tms.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1221. or tms.contact_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1222. or tms.return_address LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1223. )
  1224. </if>
  1225. </where>
  1226. union all
  1227. select cus.cus_id as "objId",
  1228. cus.cus_code as "objCode",
  1229. cus.cus_name as "objName",
  1230. '客户' as "objTypeName",
  1231. 2 as "objType",
  1232. cus.flg_valid as "flgValid",
  1233. cus.cus_phone as "phone",
  1234. cus.address_full as "addressFull"
  1235. from dkic_b.t_mst_customer cus
  1236. <where>
  1237. cus.cp_id = #{cpId}
  1238. <if test="flgValid">
  1239. AND cus.flg_valid
  1240. </if>
  1241. <if test="objCode != null and objCode != ''">
  1242. AND cus.cus_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1243. </if>
  1244. <if test="objName != null and objName != ''">
  1245. AND cus.cus_name LIKE concat('%',my_ex.likequery(#{objName}),'%')
  1246. </if>
  1247. <if test="searchText != null and searchText != ''">
  1248. AND ( cus.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1249. or cus.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1250. or cus.address_full LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1251. )
  1252. </if>
  1253. </where>
  1254. ) tt
  1255. <where>
  1256. <if test="objType != null and objType != ''">
  1257. AND tt."objType" = #{objType}
  1258. </if>
  1259. </where>
  1260. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1261. limit #{end} offset #{start}
  1262. </if>
  1263. </select>
  1264. <!--获取供应商和客户数据分页-->
  1265. <select id="getSupplierAndCustomerByPageCount" resultType="Long">
  1266. select count(1) from(
  1267. select tms.sup_id as "objId",
  1268. tms.sup_code as "objCode",
  1269. tms.sup_name as "objName",
  1270. '供应商' as "objTypeName",
  1271. 1 as "objType",
  1272. tms.flg_valid as "flgValid",
  1273. null as "phone",
  1274. null as "addressFull"
  1275. from dkic_b.t_mst_supplier tms
  1276. <where>
  1277. tms.sup_type = '供应商类别-采购'
  1278. and tms.cp_id = #{cpId}
  1279. <if test="flgValid">
  1280. AND tms.flg_valid
  1281. </if>
  1282. <if test="objCode != null and objCode != ''">
  1283. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1284. </if>
  1285. <if test="objName != null and objName != ''">
  1286. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1287. </if>
  1288. <if test="searchText != null and searchText != ''">
  1289. AND (
  1290. tms.sup_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1291. or tms.contact_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1292. or tms.return_address LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1293. )
  1294. </if>
  1295. </where>
  1296. union all
  1297. select cus.cus_id as "objId",
  1298. cus.cus_code as "objCode",
  1299. cus.cus_name as "objName",
  1300. '客户' as "objTypeName",
  1301. 2 as "objType",
  1302. cus.flg_valid as "flgValid",
  1303. cus.cus_phone as "phone",
  1304. cus.address_full as "addressFull"
  1305. from dkic_b.t_mst_customer cus
  1306. <where>
  1307. and cus.cp_id = #{cpId}
  1308. <if test="flgValid">
  1309. AND cus.flg_valid
  1310. </if>
  1311. <if test="objCode != null and objCode != ''">
  1312. AND cus.cus_code LIKE concat('%',my_ex.likequery(#{objCode}),'%')
  1313. </if>
  1314. <if test="objName != null and objName != ''">
  1315. AND cus.cus_name LIKE concat('%',my_ex.likequery(#{objName}),'%')
  1316. </if>
  1317. <if test="searchText != null and searchText != ''">
  1318. AND ( cus.cus_name LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1319. or cus.cus_phone LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1320. or cus.address_full LIKE concat('%',my_ex.likequery(#{searchText}),'%')
  1321. )
  1322. </if>
  1323. </where>
  1324. ) tt
  1325. <where>
  1326. <if test="objType != null and objType != ''">
  1327. AND tt."objType" = #{objType}
  1328. </if>
  1329. </where>
  1330. </select>
  1331. <!-- 获取用户 -->
  1332. <select id="getStaff" resultType="java.util.Map">
  1333. select
  1334. s.staff_name as "staffName"
  1335. , s.staff_code as "staffCode"
  1336. , sys.f_code_name(s.staff_code, s.staff_name) AS "staffCodeName"
  1337. , s.staff_id as "staffId"
  1338. , s.staff_id AS "id"
  1339. , s.org_id as "orgId"
  1340. , o.org_name as "orgName"
  1341. , c.cp_name as "cpName"
  1342. FROM dkic_b.t_mst_staff s
  1343. left join dkic_b.t_mst_org o on o.org_id = s.org_id
  1344. left join dkic_a.t_a_company c on c.cp_id = s.cp_id
  1345. where
  1346. s.flg_valid
  1347. and s.hr_status = 1
  1348. and s.cp_id = #{cpId}
  1349. <if test="staffCode !=null and staffCode !=''">
  1350. AND s.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
  1351. </if>
  1352. <if test="staffName !=null and staffName !=''">
  1353. AND s.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  1354. </if>
  1355. <if test="orgId !=null">
  1356. AND s.org_id = #{orgId}
  1357. </if>
  1358. <if test="orgName !=null and orgName !=''">
  1359. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1360. </if>
  1361. </select>
  1362. <!-- 获取用户 -->
  1363. <select id="getStaffPurviewType" resultType="java.util.Map">
  1364. select
  1365. s.staff_name as "staffName"
  1366. , s.staff_code as "staffCode"
  1367. , s.staff_id as "staffId",
  1368. COALESCE ( ( SELECT flg_nolimit FROM dkic_b.t_mst_staff_purview WHERE staff_id = #{staffId} :: UUID and purview_code = #{purviewCode}), FALSE ) "flgNolimit",
  1369. CASE WHEN ss.staff_id IS NULL THEN FALSE ELSE TRUE END AS "checked"
  1370. FROM dkic_b.t_mst_staff s
  1371. left JOIN dkic_b.t_mst_staff ss ON ss.staff_id = s.staff_id and s.staff_id::uuid = any ( (
  1372. select data_ids from dkic_b.t_mst_staff_purview where staff_id = #{staffId}::uuid and purview_code = #{purviewCode})::uuid[])
  1373. where
  1374. s.flg_valid
  1375. and s.hr_status = 1
  1376. and s.cp_id = #{cpId}
  1377. <if test="staffCode !=null and staffCode !=''">
  1378. AND s.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
  1379. </if>
  1380. <if test="staffName !=null and staffName !=''">
  1381. AND s.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  1382. </if>
  1383. </select>
  1384. <!-- 获取组织机构 -->
  1385. <select id="getOrganization" resultType="java.util.Map">
  1386. select o.org_id as "orgId"
  1387. , o.org_code as "orgCode"
  1388. , o.org_name as "orgName"
  1389. , sys.f_code_name(o.org_code, o.org_name) AS "orgCodeName"
  1390. from dkic_b.t_mst_org o
  1391. where
  1392. o.flg_valid
  1393. and o.cp_id = #{cpId}
  1394. <if test="orgCode !=null and orgCode !=''">
  1395. AND o.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1396. </if>
  1397. <if test="orgName !=null and orgName !=''">
  1398. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1399. </if>
  1400. order by o.level_code
  1401. </select>
  1402. <!-- 获取组织机构分页 -->
  1403. <select id="getOrganizationByPage" resultType="java.util.Map">
  1404. select o.org_id as "orgId"
  1405. , o.org_code as "orgCode"
  1406. , o.org_name as "orgName"
  1407. , sys.f_code_name(o.org_code, o.org_name) AS "orgCodeName"
  1408. from dkic_b.t_mst_org o
  1409. where
  1410. o.flg_valid
  1411. and o.cp_id = #{cpId}
  1412. <if test="orgCode !=null and orgCode !=''">
  1413. AND o.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1414. </if>
  1415. <if test="orgName !=null and orgName !=''">
  1416. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1417. </if>
  1418. order by o.level_code
  1419. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1420. limit #{end} offset #{start}
  1421. </if>
  1422. </select>
  1423. <!-- 获取组织机构分个数-->
  1424. <select id="getOrganizationCount" resultType="java.lang.Long">
  1425. SELECT count(1)
  1426. from dkic_b.t_mst_org o
  1427. where
  1428. o.flg_valid
  1429. and o.cp_id = #{cpId}
  1430. <if test="orgCode !=null and orgCode !=''">
  1431. AND o.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1432. </if>
  1433. <if test="orgName !=null and orgName !=''">
  1434. AND o.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1435. </if>
  1436. </select>
  1437. <!-- 获取资金账户(下拉)-->
  1438. <select id="getMac" resultType="java.util.Map">
  1439. select tmma.mac_id as "macId",
  1440. tmma.mac_code as "macCode",
  1441. tmma.mac_name as "macName",
  1442. tmma.mac_type as "macType",
  1443. tmma.balance,
  1444. tmma.display_no as "displayNo",
  1445. tmma.flg_default as "flgDefault",
  1446. tmma.mac_receipt_code as "macReceiptCode",
  1447. tmma.remarks
  1448. from dkic_b.t_mst_money_account tmma
  1449. where tmma.flg_valid
  1450. and tmma.cp_id = #{cpId}
  1451. <if test="macCode !=null and macCode !=''">
  1452. AND tmma.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1453. </if>
  1454. <if test="macName !=null and macName !=''">
  1455. AND tmma.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1456. </if>
  1457. order by tmma.display_no
  1458. </select>
  1459. <!-- 获取资金账户(放大镜) -->
  1460. <select id="getMoneyAccount" resultType="java.util.Map">
  1461. select tmma.mac_id as "macId",
  1462. tmma.mac_code as "macCode",
  1463. tmma.mac_name as "macName",
  1464. tmma.mac_type as "macType",
  1465. tmma.balance,
  1466. tmma.display_no as "displayNo",
  1467. tmma.flg_default as "flgDefault",
  1468. tmma.mac_receipt_code as "macReceiptCode",
  1469. tmma.remarks
  1470. from dkic_b.t_mst_money_account tmma
  1471. where tmma.flg_valid
  1472. and tmma.cp_id = #{cpId}
  1473. <if test="macCode !=null and macCode !=''">
  1474. AND tmma.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1475. </if>
  1476. <if test="macName !=null and macName !=''">
  1477. AND tmma.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1478. </if>
  1479. order by tmma.display_no
  1480. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1481. limit #{end} offset #{start}
  1482. </if>
  1483. </select>
  1484. <!-- 获取资金账户(放大镜)个数 -->
  1485. <select id="getMoneyAccountCountByPage" resultType="Long">
  1486. SELECT
  1487. count(1)
  1488. from dkic_b.t_mst_money_account tmma
  1489. where tmma.flg_valid
  1490. and tmma.cp_id = #{cpId}
  1491. <if test="macCode !=null and macCode !=''">
  1492. AND tmma.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1493. </if>
  1494. <if test="macName !=null and macName !=''">
  1495. AND tmma.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1496. </if>
  1497. </select>
  1498. <!-- 查询表core.t_m_organization,查询业务部门多业务归属 -->
  1499. <select id="selectMultiOrg" resultType="java.util.Map">
  1500. select t.org_id as "orgId",
  1501. t.org_code as "orgCode",
  1502. t.org_name as "orgName",
  1503. case when mo.allocation_ratio is null then 100 else mo.allocation_ratio end as "allocationRatio",
  1504. case when mo.multi_id is null then 0 else 1 end as "selectFlag",
  1505. case when mo.owner_type = '归属类型-主部门' then true else false end as "ownerFlag"
  1506. from dkic_b.t_mst_org t
  1507. left join (SELECT tpmo.owner_id, tpmo.allocation_ratio, tpmo.multi_id, tpmo.owner_type
  1508. from dkic_b.t_psi_order tpo
  1509. inner join dkic_b.t_psi_multi_owner tpmo
  1510. on tpo.order_id = tpmo.order_id
  1511. where tpmo.flg_valid
  1512. and tpmo.owner_type = any (array ['归属类型-主部门' , '归属类型-从部门'])
  1513. and tpo.order_id = #{orderId} ::uuid) mo
  1514. on mo.owner_id = t.org_id
  1515. where t.flg_valid
  1516. <if test="orgCode !=null and orgCode !=''">
  1517. AND t.org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  1518. </if>
  1519. <if test="orgName !=null and orgName !=''">
  1520. AND t.org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  1521. </if>
  1522. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1523. limit #{end} offset #{start}
  1524. </if>
  1525. </select>
  1526. <!-- 查询表core.t_m_user,查询员工多业务归属 -->
  1527. <select id="selectMultiStaff" resultType="java.util.Map">
  1528. select t.staff_id as "staffId",
  1529. t.staff_code as "staffCode",
  1530. t.staff_name as "staffName",
  1531. tmo.org_name as "orgName",
  1532. case when mo.allocation_ratio is null then 100 else mo.allocation_ratio end as "allocationRatio",
  1533. case when mo.multi_id is null then 0 else 1 end as "selectFlag",
  1534. case when mo.owner_type = '归属类型-主员工' then true else false end as "ownerFlag"
  1535. from dkic_b.t_mst_staff t
  1536. left join dkic_b.t_mst_org as tmo on tmo.org_id = t.org_id
  1537. left join (SELECT tpmo.owner_id, tpmo.allocation_ratio, tpmo.multi_id, tpmo.owner_type
  1538. from dkic_b.t_psi_order tpo
  1539. inner join dkic_b.t_psi_multi_owner tpmo
  1540. on tpo.order_id = tpmo.order_id
  1541. where tpmo.flg_valid
  1542. and tpmo.owner_type = any (array ['归属类型-主员工' , '归属类型-从员工'])
  1543. and tpo.order_id = #{orderId} ::uuid
  1544. ) mo
  1545. on mo.owner_id = t.staff_id
  1546. where t.flg_valid
  1547. <if test="staffCode!=null and staffCode!='' ">
  1548. and t.staff_code LIKE concat('%',my_ex.likequery(#{staffCode}),'%')
  1549. </if>
  1550. <if test="staffName!=null and staffName!='' ">
  1551. and t.staff_name LIKE concat('%',my_ex.likequery(#{staffName}),'%')
  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_org_wh,查询组织仓库 -->
  1558. <select id="selectMultiWarehouse" resultType="java.util.Map">
  1559. select t.wh_id as "whId",
  1560. t.wh_code as "whCode",
  1561. t.wh_name as "whName",
  1562. case when mo.wh_id is null then 0 else 1 end as "selectFlag",
  1563. case when mo.wh_id is null then false else mo.flg_default end as "ownerFlag"
  1564. from dkic_b.t_mst_warehouse t
  1565. left join (SELECT orgwh.flg_default, orgwh.wh_id
  1566. from dkic_b.t_mst_org org
  1567. inner join dkic_b.t_mst_org_wh orgwh
  1568. on org.org_id = orgwh.org_id
  1569. where org.flg_valid
  1570. and org.org_id = #{orgId} ::uuid) mo
  1571. on mo.wh_id = t.wh_id
  1572. where t.flg_valid
  1573. <if test="whCode !=null and whCode !=''">
  1574. AND t.wh_code LIKE concat('%',my_ex.likequery(#{whCode}),'%')
  1575. </if>
  1576. <if test="whName !=null and whName !=''">
  1577. AND t.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1578. </if>
  1579. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1580. limit #{end} offset #{start}
  1581. </if>
  1582. </select>
  1583. <!-- 查询表core.t_m_org_mac,查询组织资金账户 -->
  1584. <select id="selectMultiMoneyAccount" resultType="java.util.Map">
  1585. select t.mac_id as "macId",
  1586. t.mac_code as "macCode",
  1587. t.mac_name as "macName",
  1588. case when mo.mac_id is null then 0 else 1 end as "selectFlag",
  1589. case when mo.mac_id is null then false else mo.flg_default end as "ownerFlag"
  1590. from dkic_b.t_mst_money_account t
  1591. left join (SELECT orgmac.flg_default,orgmac.mac_id
  1592. from dkic_b.t_mst_org org
  1593. inner join dkic_b.t_mst_org_mac orgmac
  1594. on org.org_id = orgmac.org_id
  1595. where org.flg_valid
  1596. and org.org_id = #{orgId} ::uuid) mo
  1597. on mo.mac_id = t.mac_id
  1598. where t.flg_valid
  1599. <if test="macCode !=null and macCode !=''">
  1600. AND t.mac_code LIKE concat('%',my_ex.likequery(#{macCode}),'%')
  1601. </if>
  1602. <if test="macName !=null and macName !=''">
  1603. AND t.mac_name LIKE concat('%',my_ex.likequery(#{macName}),'%')
  1604. </if>
  1605. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1606. limit #{end} offset #{start}
  1607. </if>
  1608. </select>
  1609. <!-- 查询库存 -->
  1610. <select id="getGoodsForPurchaseReturn" resultType="java.util.Map">
  1611. select tpi.inv_id as "invId",
  1612. tpi.sku_id as "skuId",
  1613. tmgs.sku_code as "skuCode",
  1614. tmgs.sku_name as "skuName",
  1615. tmgs.sku_model as "skuModel",
  1616. tmgs.brand_id as "brandId",
  1617. tmgb.brand_name as "brandName",
  1618. tmgs.category_id as "categoryId",
  1619. tmgc.cat_name as "categoryName",
  1620. tmgs.unit_id as "unitId",
  1621. tmgu.unit_name as "unitName",
  1622. tmgs.sub_unit_id as "subUnitId",
  1623. tmgs.conversion_factor as "conversionFactor",
  1624. tmgs.series_id as "seriesId",
  1625. tmgseries.series_name as "seriesName",
  1626. tmgs.sku_spec as "skuSpec",
  1627. tmgs.price_purchase as "pricePurchase",
  1628. tmgs.price_standard as "priceStandard",
  1629. tmgs.price_wholesale as "priceWholesale",
  1630. tmgs.price_limited as "priceLimited",
  1631. tmgs.sku_images as "skuImages",
  1632. tpi.non_std_code as "nonStdCode",
  1633. tpi.inv_qty as "invQty",
  1634. tpi.outing_qty as "outingQty",
  1635. tpi.usable_qty as "usableQty",
  1636. tpi.wh_id as "whId",
  1637. tmw.wh_code as "whCode",
  1638. tmw.wh_name as "whName",
  1639. tpi.cost_price as "costPrice",
  1640. tpi.cost_amt as "costAmt",
  1641. tpi.remarks
  1642. from dkic_b.t_psi_inventory as tpi
  1643. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1644. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  1645. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  1646. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  1647. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  1648. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  1649. where tpi.flg_valid
  1650. AND tpi.cp_id = #{cpId}
  1651. <if test="skuId != null">
  1652. AND tpi.sku_id = #{skuId} ::uuid
  1653. </if>
  1654. <if test="nonStdCode != null">
  1655. AND tpi.non_std_code = #{nonStdCode}
  1656. </if>
  1657. <if test="skuCode != null">
  1658. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1659. </if>
  1660. <if test="skuName != null">
  1661. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1662. </if>
  1663. <if test="whName != null">
  1664. AND tmgs.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  1665. </if>
  1666. <if test="whId != null">
  1667. AND tpi.wh_id = #{whId} ::uuid
  1668. </if>
  1669. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  1670. limit #{end} offset #{start}
  1671. </if>
  1672. </select>
  1673. <!-- 查询库存个数 -->
  1674. <select id="getGoodsForPurchaseReturnByPage" resultType="Long">
  1675. SELECT
  1676. count(1)
  1677. from dkic_b.t_psi_inventory as tpi
  1678. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1679. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_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. </select>
  1698. <!--范围权限类型-->
  1699. <select id="getPurviewType" resultType="java.util.Map">
  1700. select tpt.purview_name_i18n as purviewName,
  1701. tpt.purview_code as "code",
  1702. "row_number"() OVER (ORDER BY tpt.display_no) as "id",
  1703. sys.f_get_name_i18n(tpt.purview_name_i18n, #{i18n}) AS name
  1704. from sys.t_purview_type tpt
  1705. where tpt.flg_valid
  1706. order by tpt.display_no
  1707. </select>
  1708. <select id="getInventoryByList" resultType="java.util.Map">
  1709. select tpi.inv_id as "invId",
  1710. tpi.sku_id as "skuId",
  1711. tpi.non_std_code as "nonStdCode",
  1712. tpi.inv_qty as "invQty",
  1713. tpi.outing_qty as "outingQty",
  1714. tpi.usable_qty as "usableQty",
  1715. tpi.wh_id as "whId",
  1716. tmw.wh_name as "whName",
  1717. tpi.remarks
  1718. from dkic_b.t_psi_inventory as tpi
  1719. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  1720. where tpi.flg_valid
  1721. AND tpi.cp_id = #{cpId} AND
  1722. <foreach collection="skuIdNonStdCodeWhIdList" item="condition" separator=" OR ">
  1723. <if test="condition.skuId != null">
  1724. tpi.sku_id = #{condition.skuId} ::uuid
  1725. </if>
  1726. <if test="condition.nonStdCode != null">
  1727. AND tpi.non_std_code = #{condition.nonStdCode}
  1728. </if>
  1729. <if test="condition.whId != null">
  1730. AND tpi.wh_id = #{condition.whId} ::uuid
  1731. </if>
  1732. </foreach>
  1733. </select>
  1734. <!-- 查询标签打印项目 -->
  1735. <select id="getLabelPrintItem" resultType="java.util.Map">
  1736. select
  1737. item_code as "itemCode",
  1738. sys.f_get_name_i18n(item_name_i18n,#{i18n}) as "itemName",
  1739. doc_name as "docName",
  1740. item_type as "itemType",
  1741. item_style as "itemStyle",
  1742. item_sample as "itemSample",
  1743. data_key as "dataKey",
  1744. remarks as "remarks"
  1745. from sys.t_label_print_item
  1746. where flg_valid
  1747. <if test="docName">
  1748. and doc_name = #{docName}
  1749. </if>
  1750. order by display_no
  1751. </select>
  1752. <!--获取组织仓库-->
  1753. <select id="getOrgWh" resultType="java.util.Map">
  1754. select t.wh_id as "whId",
  1755. tmw.wh_name as "whName",
  1756. t.flg_default as "flgDefault"
  1757. from dkic_b.t_mst_org_wh t
  1758. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = t.wh_id
  1759. where t.cp_id = #{cpId}
  1760. and t.org_id = #{orgId}::uuid
  1761. order by t.display_no
  1762. </select>
  1763. <!-- 获取商品(其他入库开单用) -->
  1764. <select id="getGoodsForInto" resultType="java.util.Map">
  1765. select tmgs.sku_id as "skuId",
  1766. tmgs.sku_code as "skuCode",
  1767. tmgs.sku_name as "skuName",
  1768. tmgs.sku_model as "skuModel",
  1769. tmgs.brand_id as "brandId",
  1770. tmgb.brand_name as "brandName",
  1771. tmgs.category_id as "categoryId",
  1772. tmgc.cat_name as "categoryName",
  1773. tmgs.unit_id as "unitId",
  1774. tmgu.unit_name as "unitName",
  1775. tmgs.sub_unit_id as "subUnitId",
  1776. tmgs.conversion_factor as "conversionFactor",
  1777. tmgs.series_id as "seriesId",
  1778. tmgseries.series_name as "seriesName",
  1779. tmgs.sku_spec as "skuSpec",
  1780. tmgs.price_purchase as "priceInto",
  1781. tmgs.price_standard as "priceStandard",
  1782. tmgs.price_wholesale as "priceWholesale",
  1783. tmgs.price_limited as "priceLimited",
  1784. tmgs.sku_images as "skuImages",
  1785. tmgs.remarks
  1786. from dkic_b.t_mst_goods_sku as tmgs
  1787. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  1788. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  1789. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  1790. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  1791. where tmgs.flg_valid
  1792. AND tmgs.cp_id = #{cpId}
  1793. <if test="skuCode != null">
  1794. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1795. </if>
  1796. <if test="skuName != null">
  1797. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1798. </if>
  1799. <if test="categoryId != null">
  1800. AND tmgs.category_id = #{categoryId}::uuid
  1801. </if>
  1802. </select>
  1803. <!-- 获取商品(其他入库开单用)(数量) -->
  1804. <select id="getGoodsForIntoCountByPage" resultType="Long">
  1805. SELECT
  1806. count(1)
  1807. from dkic_b.t_mst_goods_sku as tmgs
  1808. where tmgs.flg_valid
  1809. AND tmgs.cp_id = #{cpId}
  1810. <if test="skuCode != null">
  1811. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  1812. </if>
  1813. <if test="skuName != null">
  1814. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  1815. </if>
  1816. </select>
  1817. <select id="selectDictionaryData" resultType="java.util.Map">
  1818. select dd.data_id as "dataId",
  1819. dd.data_id as "id",
  1820. dd.dict_code as "dictCode",
  1821. dd.data_code as "dataCode",
  1822. dd.data_value as "dataValue",
  1823. dd.flg_default as "flgDefault"
  1824. from dkic_b.t_mst_dictionary_data as dd
  1825. where dd.flg_valid
  1826. and dd.cp_id = #{cpId}
  1827. and dd.dict_code = #{dictCode}
  1828. and dd.data_value = #{dataValue}
  1829. </select>
  1830. <!-- 销售分析-我的 门店助手的 销售金额 收款金额 库存成本 -->
  1831. <select id="getHomeOrderRecCost" resultType="java.util.Map">
  1832. select dkic_b.f_get_home_order_rec_cost(#{cpId},#{dateBegin}::date,#{dateEnd}::date)
  1833. </select>
  1834. </mapper>