CommonMapper.xml 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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 flg_valid
  9. <if test="ftyId != null">
  10. and fty_id = #{ftyId}
  11. </if>
  12. <if test="otherCond">
  13. and ${otherCond}
  14. </if>
  15. <!--数据字典-->
  16. <if test="dictCode != null">
  17. and dict_code = #{dictCode}
  18. </if>
  19. </select>
  20. <!--获取编码-->
  21. <select id="getUniqueCode" resultType="java.util.Map">
  22. select out_id AS "outId", out_code AS "outNote"
  23. from dkic_b.f_create_code_id(#{cpId}, #{docName});
  24. </select>
  25. <!--获取单号-->
  26. <select id="getUniqueNote" resultType="java.util.Map">
  27. select out_id AS "outId", out_note AS "outNote"
  28. from dkic_b.f_create_note_id(#{cpId}, #{docName});
  29. </select>
  30. <!-- 获取用户菜单-->
  31. <select id="getMenuByUser" resultType="java.util.Map">
  32. select menu_uuid AS "menuUuid",
  33. name AS "name",
  34. menu_name AS "menuName",
  35. parent_uuid AS "parentUuid",
  36. menu_type AS "menuType",
  37. flg_menu AS "flgMenu",
  38. object_code AS "objectCode",
  39. object_path AS "objectPath",
  40. object_icon AS "icon",
  41. object_id AS "objectId",
  42. menu_tags AS "menuTags",
  43. level_code AS "levelCode",
  44. flg_same_route AS "flgSameRoute",
  45. flg_choose_id AS "flgChooseId",
  46. flg_auto_query AS "flgAutoQuery",
  47. page_grid_info AS "pageGridInfo",
  48. grade_code AS "gradeCode",
  49. grade_level AS "gradeLevel",
  50. is_vip AS "isVip",
  51. #{appCode} AS "appCode",
  52. menu_uuid AS "id",
  53. parent_uuid AS "parentId"
  54. from
  55. dkic_b.f_get_user_menu(#{appCode}, #{userId } ::uuid,#{cpId},#{lang})
  56. </select>
  57. <!--查用户功能权限-->
  58. <select id="getUserFunction" resultType="java.util.Map">
  59. select appm.menu_uuid AS "menuUuid"
  60. , appm.menu_name as name
  61. , sys.f_get_name_i18n_lang(appm.menu_name_i18n, #{i18n}) as "menuName"
  62. , rr.fun_uuid AS "funUuid"
  63. , appm.object_code AS "objectCode"
  64. , appm.menu_type AS "menuType"
  65. from sys.t_app_menu appm
  66. inner join core.t_user_fun rr
  67. on rr.fun_uuid = appm.fun_uuid
  68. where appm.flg_valid
  69. and appm.app_code = #{appCode}
  70. and appm.menu_type IN (1, 2)
  71. and rr.user_id = #{userId};
  72. </select>
  73. <!--查询用于隐藏列信息-->
  74. <select id="getUserTableInfo" resultType="java.util.Map">
  75. select tuts.code,
  76. tuts.table_type AS "tableType",
  77. tuts.table_ref AS "tableRef",
  78. tuts.columns
  79. from pset.t_user_table_set tuts
  80. where tuts.flg_valid
  81. and tuts.user_id = #{userId};
  82. </select>
  83. <!--查导航菜单(自定义报表用)-->
  84. <select id="getMenuNavigation" resultType="java.util.Map">
  85. select appm.menu_uuid AS "menuUuid"
  86. ,sys.f_get_name_i18n_lang(appm.menu_name_i18n,#{i18n}) as "menuName"
  87. ,appm.parent_uuid AS "parentUuid"
  88. from sys.t_app_menu appm
  89. where appm.flg_valid
  90. <if test="parentUuid">
  91. and appm.parent_uuid = #{parentUuid} ::uuid
  92. </if>
  93. and appm.app_code = 'WEB-MAIN'
  94. and appm.menu_type = 0
  95. </select>
  96. <!-- 获取应用-->
  97. <select id="getApplication" resultType="java.util.Map">
  98. select
  99. app_code as "appCode",
  100. app_name as "appName"
  101. from sys.t_application
  102. </select>
  103. <!--获取单据-->
  104. <select id="getDoc" resultType="java.util.Map">
  105. SELECT
  106. tsd.doc_code AS "docCode",
  107. sys.f_get_name_i18n_lang ( tsd.doc_name_i18n, #{i18n}) AS "docName"
  108. FROM
  109. sys.t_s_doc tsd
  110. WHERE
  111. tsd.flg_valid
  112. <if test="flgApproval!=null">
  113. and tsd.flg_approval = #{flgApproval}
  114. </if>
  115. </select>
  116. <!-- 获取数据种类 -->
  117. <select id="getDataKind" resultType="java.util.Map">
  118. select kind_code AS "kindCode",
  119. sys.f_get_name_i18n(kind_name_i18n,#{i18n}) as "kindName",
  120. sys.f_get_name_i18n(kind_desc,#{i18n}) as "gradeKindDesc",
  121. kind_type AS "kindType",
  122. kind_tags AS "kindTags",
  123. display_no AS "displayNo",
  124. kind_code AS "id",
  125. remarks
  126. from sys.t_data_kind
  127. where flg_valid
  128. <if test="kindType != null">
  129. AND kind_type = #{kindType}
  130. </if>
  131. <if test="usedFlag != null">
  132. AND kind_tags -> 'used' ?? '标签'
  133. </if>
  134. <if test="kindTag != null">
  135. AND kind_tags -> 'used' ?? #{kindTag}
  136. </if>
  137. <if test="kindCodeList != null and kindCodeList.size()>0">
  138. AND kind_code =any(#{kindCodeList,typeHandler=StringListTypeHandler})
  139. </if>
  140. order by display_no
  141. </select>
  142. <!-- 获取组织部门 -->
  143. <select id="getOrg" resultType="java.util.Map">
  144. select org_Id AS "orgId",
  145. org_code AS "orgCode",
  146. org_name AS "orgName",
  147. org_Id AS "id",
  148. parent_id AS "parentId",
  149. top_Id AS "topId",
  150. display_no AS "displayNo",
  151. remarks
  152. from dkic_b.t_mst_org
  153. where flg_valid
  154. and cp_id = #{cpId}
  155. <if test="topId != null">
  156. AND top_id = #{topId}
  157. </if>
  158. <if test="orgId != null">
  159. AND org_id != #{orgId}
  160. </if>
  161. <if test="orgCode != null">
  162. AND org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  163. </if>
  164. <if test="orgName != null">
  165. AND org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  166. </if>
  167. order by display_no
  168. </select>
  169. <!-- t_mst_org,(条件查询)个数 -->
  170. <select id="getOrgCountByPage" resultType="Long">
  171. SELECT
  172. count(1)
  173. from dkic_b.t_mst_org
  174. where flg_valid
  175. and cp_id = #{cpId}
  176. <if test="topId != null">
  177. AND top_id = #{topId}
  178. </if>
  179. <if test="orgId != null">
  180. AND org_id != #{orgId}
  181. </if>
  182. <if test="orgCode != null">
  183. AND org_code LIKE concat('%',my_ex.likequery(#{orgCode}),'%')
  184. </if>
  185. <if test="orgName != null">
  186. AND org_name LIKE concat('%',my_ex.likequery(#{orgName}),'%')
  187. </if>
  188. </select>
  189. <!-- 获取角色 -->
  190. <select id="getRole" resultType="java.util.Map">
  191. select role_Id AS "roleId",
  192. role_name AS "roleName",
  193. display_no AS "displayNo",
  194. remarks
  195. from dkic_b.t_mst_role
  196. where cp_id = #{cpId}
  197. and flg_valid
  198. order by display_no
  199. </select>
  200. <!-- 获取员工 -->
  201. <select id="getStaffByPage" resultType="java.util.Map">
  202. select staff.staff_id AS "staffId",
  203. staff.staff_code AS "staffCode",
  204. staff.staff_name AS "staffName",
  205. sys.f_code_name(staff.staff_code, staff.staff_name) AS "staffCodeName",
  206. staff.remarks
  207. from dkic_b.t_mst_staff AS staff
  208. where staff.flg_valid
  209. and staff.cp_id =#{cpId}
  210. <if test="staffCode != null and staffCode != ''">
  211. And position (#{staffCode} in staff.staff_code)>0
  212. </if>
  213. <if test="staffName != null and staffName != ''">
  214. And position (#{staffName} in staff.staff_name)>0
  215. </if>
  216. order by staff.staff_code
  217. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  218. limit #{end} offset #{start}
  219. </if>
  220. </select>
  221. <!-- 查询表t_user,(条件查询)个数 -->
  222. <select id="getStaffCountByPage" resultType="Long">
  223. SELECT
  224. count(1)
  225. from dkic_b.t_mst_staff AS staff
  226. where staff.flg_valid
  227. and staff.cp_id =#{cpId}
  228. <if test="staffCode != null and staffCode != ''">
  229. And position (#{staffCode} in staff.staff_code)>0
  230. </if>
  231. <if test="staffName != null and staffName != ''">
  232. And position (#{staffName} in staff.staff_name)>0
  233. </if>
  234. </select>
  235. <!-- 函数查询单个系统参数-->
  236. <select id="getSettingValue" resultType="String">
  237. select core.f_get_setting_value(#{code}, #{ftyId})
  238. </select>
  239. <!-- 函数查询多个系统参数-->
  240. <select id="getSettingValues" resultType="Map">
  241. select core.f_get_setting_values(
  242. #{codes, typeHandler=StringListTypeHandler}, #{ftyId})
  243. </select>
  244. <!-- 查询系统参数分类 -->
  245. <select id="getSettingKind" resultType="java.util.Map">
  246. select sk.kind_code as "classCode",
  247. sys.f_get_name_i18n_lang(sk.kind_name_i18n, #{i18n}) as "className",
  248. sk.display_no as "displayNo"
  249. from sys.t_setting_kind as sk
  250. where sk.flg_valid
  251. order by sk.display_no
  252. </select>
  253. <!-- 获取数据字典 -->
  254. <select id="getDictionaryData" resultType="java.util.Map">
  255. select dd.data_id as "dataId",
  256. dd.data_id as "id",
  257. dd.dict_code as "dictCode",
  258. dd.data_code as "dataCode",
  259. dd.data_value as "dataValue",
  260. dd.flg_default as "flgDefault"
  261. from dkic_b.t_mst_dictionary_data as dd
  262. where dd.flg_valid
  263. and dd.cp_id = #{cpId}
  264. and dd.dict_code = #{dictCode}
  265. order by dd.display_no
  266. </select>
  267. <!-- 获取数据字典项目 -->
  268. <select id="getDictionaryItemData" resultType="java.util.Map">
  269. SELECT stdi.dict_code AS "dictCode",
  270. sys.f_get_name_i18n_lang(stdi.dict_name_i18n, 'zh_CN') AS "dictName"
  271. FROM sys.t_dictionary_item stdi
  272. WHERE stdi.flg_valid
  273. AND stdi.level_no NOT IN ('1')
  274. </select>
  275. <!-- 获取数据类型 -->
  276. <select id="getValueKind" resultType="java.util.Map">
  277. select tvk.kind_code AS "kindCode",
  278. tvk.kind_name as "kindName",
  279. sys.f_get_name_i18n_lang(tvk.kind_name_i18n,#{i18n}) AS "kindLabel"
  280. from sys.t_value_kind as tvk
  281. where tvk.flg_valid
  282. <if test="used != null and used != ''">
  283. and #{used} = ANY (tvk.used)
  284. </if>
  285. order by tvk.display_no
  286. </select>
  287. <!-- 获取仓库 -->
  288. <select id="getWarehouse" resultType="java.util.Map">
  289. SELECT tmw.wh_id as "whId"
  290. ,tmw.wh_id AS "id"
  291. ,tmw.wh_name as "whName"
  292. ,tmw.wh_code as "whCode"
  293. ,tmw.flg_default as "flgDefault"
  294. FROM dkic_b.t_mst_warehouse tmw
  295. WHERE tmw.cp_id = #{cpId}
  296. and tmw.flg_valid
  297. <if test="whCode!=null and whCode!=''">
  298. and position(#{whCode} in tmw.wh_code) > 0
  299. </if>
  300. <if test="whName!=null and whName!=''">
  301. and position(#{whName} in tmw.wh_name) > 0
  302. </if>
  303. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  304. limit #{end} offset #{start}
  305. </if>
  306. </select>
  307. <!-- 获取商品 -->
  308. <select id="getGoods" resultType="java.util.Map">
  309. select tmgs.sku_id as "skuId",
  310. tmgs.sku_code as "skuCode",
  311. tmgs.sku_name as "skuName",
  312. tmgs.sku_model as "skuModel",
  313. tmgs.brand_id as "brandId",
  314. tmgb.brand_name as "brandName",
  315. tmgs.category_id as "categoryId",
  316. tmgc.cat_name as "categoryName",
  317. tmgs.unit_id as "unitId",
  318. tmgu.unit_name as "unitName",
  319. tmgs.sub_unit_id as "subUnitId",
  320. tmgs.conversion_factor as "conversionFactor",
  321. tmgs.series_id as "seriesId",
  322. tmgseries.series_name as "seriesName",
  323. tmgs.sku_spec as "skuSpec",
  324. tmgs.price_purchase as "pricePurchase",
  325. tmgs.price_standard as "priceStandard",
  326. tmgs.price_wholesale as "priceWholesale",
  327. tmgs.price_limited as "priceLimited",
  328. tmgs.sku_images as "skuImages",
  329. tmgs.remarks
  330. from dkic_b.t_mst_goods_sku as tmgs
  331. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  332. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  333. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  334. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  335. where tmgs.flg_valid
  336. AND tmgs.cp_id = #{cpId}
  337. <if test="skuCode != null">
  338. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  339. </if>
  340. <if test="skuName != null">
  341. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  342. </if>
  343. </select>
  344. <!-- 获取商品个数 -->
  345. <select id="getGoodsCountByPage" resultType="Long">
  346. SELECT
  347. count(1)
  348. from dkic_b.t_mst_goods_sku as tmgs
  349. where tmgs.flg_valid
  350. AND tmgs.cp_id = #{cpId}
  351. <if test="skuCode != null">
  352. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  353. </if>
  354. <if test="skuName != null">
  355. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  356. </if>
  357. </select>
  358. <!-- 获取商品 -->
  359. <select id="getGoodsForOrder" resultType="java.util.Map">
  360. select tmgs.sku_id as "skuId",
  361. tmgs.sku_code as "skuCode",
  362. tmgs.sku_name as "skuName",
  363. tmgs.sku_model as "skuModel",
  364. tmgs.brand_id as "brandId",
  365. tmgb.brand_name as "brandName",
  366. tmgs.category_id as "categoryId",
  367. tmgc.cat_name as "categoryName",
  368. tmgs.unit_id as "unitId",
  369. tmgu.unit_name as "unitName",
  370. tmgs.sub_unit_id as "subUnitId",
  371. tmgs.conversion_factor as "conversionFactor",
  372. tmgs.series_id as "seriesId",
  373. tmgseries.series_name as "seriesName",
  374. tmgs.sku_spec as "skuSpec",
  375. tmgs.price_purchase as "pricePurchase",
  376. tmgs.price_standard as "priceStandard",
  377. tmgs.price_wholesale as "priceWholesale",
  378. tmgs.price_limited as "priceLimited",
  379. tmgs.sku_images as "skuImages",
  380. tmgs.remarks
  381. from dkic_b.t_mst_goods_sku as tmgs
  382. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  383. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  384. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  385. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  386. where tmgs.flg_valid
  387. AND tmgs.cp_id = #{cpId}
  388. <if test="skuCode != null">
  389. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  390. </if>
  391. <if test="skuName != null">
  392. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  393. </if>
  394. </select>
  395. <!-- 获取商品个数 -->
  396. <select id="getGoodsForOrderCountByPage" resultType="Long">
  397. SELECT
  398. count(1)
  399. from dkic_b.t_mst_goods_sku as tmgs
  400. where tmgs.flg_valid
  401. AND tmgs.cp_id = #{cpId}
  402. <if test="skuCode != null">
  403. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  404. </if>
  405. <if test="skuName != null">
  406. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  407. </if>
  408. </select>
  409. <!-- 获取商品(采购) -->
  410. <select id="getGoodsForPurchase" resultType="java.util.Map">
  411. select tmgs.sku_id as "skuId",
  412. tmgs.sku_code as "skuCode",
  413. tmgs.sku_name as "skuName",
  414. tmgs.sku_model as "skuModel",
  415. tmgs.brand_id as "brandId",
  416. tmgb.brand_name as "brandName",
  417. tmgs.category_id as "categoryId",
  418. tmgc.cat_name as "categoryName",
  419. tmgs.unit_id as "unitId",
  420. tmgu.unit_name as "unitName",
  421. tmgs.sub_unit_id as "subUnitId",
  422. tmgs.conversion_factor as "conversionFactor",
  423. tmgs.series_id as "seriesId",
  424. tmgseries.series_name as "seriesName",
  425. tmgs.sku_spec as "skuSpec",
  426. tmgs.price_purchase as "pricePurchase",
  427. tmgs.price_standard as "priceStandard",
  428. tmgs.price_wholesale as "priceWholesale",
  429. tmgs.price_limited as "priceLimited",
  430. tmgs.sku_images as "skuImages",
  431. tmgs.remarks
  432. from dkic_b.t_mst_goods_sku as tmgs
  433. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  434. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  435. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  436. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  437. where tmgs.flg_valid
  438. AND tmgs.cp_id = #{cpId}
  439. <if test="skuCode != null">
  440. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  441. </if>
  442. <if test="skuName != null">
  443. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  444. </if>
  445. </select>
  446. <!-- 获取商品个数(采购) -->
  447. <select id="getGoodsForPurchaseCountByPage" resultType="Long">
  448. SELECT
  449. count(1)
  450. from dkic_b.t_mst_goods_sku as tmgs
  451. where tmgs.flg_valid
  452. AND tmgs.cp_id = #{cpId}
  453. <if test="skuCode != null">
  454. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  455. </if>
  456. <if test="skuName != null">
  457. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  458. </if>
  459. </select>
  460. <!-- 获取客户 -->
  461. <select id="getCustomer" resultType="java.util.Map">
  462. select tmc.cus_id as "cusId",
  463. tmc.cus_code as "cusCode",
  464. tmc.cus_name as "cusName",
  465. tmc.cus_phone as "cusPhone",
  466. tmc.address_area as "addressArea",
  467. tmc.address_name as "addressName",
  468. tmc.address_no as "addressNo",
  469. tmc.address_gcj02 as "addressGcj02",
  470. tmc.address_full as "addressFull",
  471. tmc.contact_name as "contactName",
  472. tmc.contact_phone as "contactPhone",
  473. tmc.cus_from as "cusFrom",
  474. tmdd.data_value as "cusFromName",
  475. tmc.channel_id as "channelId",
  476. tmsc.channel_name as "channelName",
  477. tmc.org_id as "orgId",
  478. tmo.org_name as "orgName",
  479. tmc.staff_id as "staffId",
  480. tms.staff_name as "staffName",
  481. tmc.report_staff as "reportStaff",
  482. reportstaff.staff_name as "reportStaffName",
  483. tmc.report_time as "reportTime",
  484. tmc.sale_status as "saleStatus",
  485. tmc.remarks as "remarks",
  486. tmc.follow_staffs as "followStaffs",
  487. tmc.last_follow_staff as "lastFollowStaff",
  488. tmc.last_follow_id as "lastFollowId",
  489. tmc.last_follow_status as "lastFollowStatus",
  490. tmc.last_follow_time as "lastFollowTime"
  491. from dkic_b.t_mst_customer as tmc
  492. inner join dkic_b.t_mst_org tmo on tmc.org_id = tmo.org_id
  493. inner join dkic_b.t_mst_staff tms on tmc.staff_id = tms.staff_id
  494. inner join dkic_b.t_mst_staff as reportstaff on tmc.report_staff = reportstaff.staff_id
  495. inner join dkic_b.t_mst_sale_channel tmsc on tmc.channel_id = tmsc.channel_id
  496. left join dkic_b.t_mst_dictionary_data tmdd on tmc.cus_from = tmdd.data_id
  497. where tmc.flg_valid
  498. AND tmc.cp_id = #{cpId}
  499. <if test="skuCode != null">
  500. AND tmc.cus_code = #{cusCode}
  501. </if>
  502. <if test="skuName != null">
  503. AND tmc.cus_name = #{cusName}
  504. </if>
  505. </select>
  506. <!-- 获取客户个数 -->
  507. <select id="getCustomerCountByPage" resultType="Long">
  508. SELECT
  509. count(1)
  510. from dkic_b.t_mst_customer as tmc
  511. where tmc.flg_valid
  512. and tmc.cp_id = #{cpId}
  513. <if test="skuCode != null">
  514. AND tmc.cus_code = #{cusCode}
  515. </if>
  516. <if test="skuName != null">
  517. AND tmc.cus_name = #{cusName}
  518. </if>
  519. </select>
  520. <!-- 获取单据Id-->
  521. <select id="getUuidSeq" resultType="object">
  522. select sys.f_uuid_seq()
  523. </select>
  524. <!-- 获取单据单号-->
  525. <select id="getDocNo" resultType="java.lang.String">
  526. select dkic_b.f_create_note(#{cpId}, #{purId}::uuid, #{docCode})
  527. </select>
  528. <!--获取供应商-->
  529. <select id="getSupplier" resultType="java.util.Map">
  530. select tms.sup_code as "supplierCode",
  531. tms.sup_name as "supplierName",
  532. tms.sup_id as "supplierId",
  533. tms.sup_type as "supplierType",
  534. tms.contact_name as "contactName",
  535. tms.contact_phone as "contactPhone",
  536. tms.flg_valid as "flgValid"
  537. from dkic_b.t_mst_supplier tms
  538. where tms.cp_id = #{cpId}
  539. <if test="supplierName!=null and supplierName!=''">
  540. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{supplierName}),'%')
  541. </if>
  542. <if test="supplierCode!=null and supplierCode!=''">
  543. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{supplierCode}),'%')
  544. </if>
  545. <if test="supplierType!=null and supplierType!=''">
  546. AND tms.sup_type LIKE concat('%',my_ex.likequery(#{supplierType}),'%')
  547. </if>
  548. order by tms.sup_code
  549. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  550. limit #{end} offset #{start}
  551. </if>
  552. <if test="limit != null and limit != 0 ">
  553. limit #{limit}
  554. </if>
  555. </select>
  556. <!--获取供应商数量-->
  557. <select id="countSupplier" resultType="java.lang.Long">
  558. select count(1)
  559. from dkic_b.t_mst_supplier tms
  560. where tms.cp_id = #{cpId}
  561. <if test="supplierName!=null and supplierName!=''">
  562. AND tms.sup_name LIKE concat('%',my_ex.likequery(#{supplierName}),'%')
  563. </if>
  564. <if test="supplierCode!=null and supplierCode!=''">
  565. AND tms.sup_code LIKE concat('%',my_ex.likequery(#{supplierCode}),'%')
  566. </if>
  567. <if test="supplierType!=null and supplierType!=''">
  568. AND tms.sup_type LIKE concat('%',my_ex.likequery(#{supplierType}),'%')
  569. </if>
  570. </select>
  571. <!--获取渠道 -->
  572. <select id="getChannel" resultType="java.util.Map">
  573. select c.channel_id as "channelId",
  574. c.channel_code as "channelCode",
  575. c.channel_name as "channelName",
  576. c.sys_code as "sysCode",
  577. c.display_no as "displayNo"
  578. from dkic_b.t_mst_sale_channel as c
  579. where c.flg_valid
  580. and c.cp_id = #{cpId}
  581. <if test="channel_code!=null and channel_code!=''">
  582. AND c.channel_code LIKE concat('%', #{channelCode}, '%')
  583. </if>
  584. <if test="channel_name!=null and channel_name!=''">
  585. AND c.channel_name LIKE concat('%', #{channelName}, '%')
  586. </if>
  587. order by c.display_no
  588. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  589. limit #{end} offset #{start}
  590. </if>
  591. <if test="limit != null and limit != 0 ">
  592. limit #{limit}
  593. </if>
  594. </select>
  595. <!-- 查询商品档案-->
  596. <select id="getGoodsBrand" resultType="java.util.Map">
  597. SELECT
  598. tmgb.flg_valid AS "flgValid",
  599. tmgb.brand_id AS "brandId", tmgb.brand_code AS "brandCode", tmgb.brand_name AS "brandName",
  600. (SELECT COALESCE(array_to_string(array_agg(tsm.sup_name), ','),'')
  601. FROM dkic_b.t_mst_supplier_brand tsmb
  602. left join dkic_b.t_mst_supplier tsm on tsm.sup_id = tsmb.sup_id
  603. WHERE tsmb.brand_id = tmgb.brand_id) AS "supplierName"
  604. FROM dkic_b.t_mst_goods_brand tmgb
  605. <where>
  606. <if test="searchText !=null">
  607. AND tmgb.brand_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  608. </if>
  609. <if test="cpId != null">
  610. AND tmgb.cp_id = #{cpId}
  611. </if>
  612. </where>
  613. order by tmgb.display_no asc
  614. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  615. limit #{end} offset #{start}
  616. </if>
  617. </select>
  618. <!-- 查询表t_mst_goods_brand,(条件查询)个数 -->
  619. <select id="countGoodsBrand" resultType="Long">
  620. SELECT
  621. count(1)
  622. FROM dkic_b.t_mst_goods_brand tmgb
  623. <where>
  624. <if test="searchText !=null">
  625. AND tmgb.brand_name LIKE concat('%', #{searchText}, '%')
  626. </if>
  627. <if test="cpId != null">
  628. AND tmgb.cp_id = #{cpId}
  629. </if>
  630. </where>
  631. </select>
  632. <!-- 查询商品种类-->
  633. <select id="getGoodsCategory" resultType="java.util.Map">
  634. SELECT
  635. cat_id AS "catId",
  636. cat_code AS "catCode",
  637. cat_name AS "catName",
  638. parent_id AS "parentId",
  639. flg_valid AS "flgValid"
  640. FROM dkic_b.t_mst_goods_category
  641. <where>
  642. <if test="searchText !=null">
  643. AND ( cat_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  644. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  645. </if>
  646. <if test="cpId != null">
  647. AND cp_id = #{cpId}
  648. </if>
  649. </where>
  650. ORDER BY display_no
  651. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  652. limit #{end} offset #{start}
  653. </if>
  654. </select>
  655. <!-- 查询商品种类的个数-->
  656. <select id="countGoodsCategory" resultType="java.lang.Long">
  657. SELECT
  658. count(1)
  659. FROM dkic_b.t_mst_goods_category
  660. <where>
  661. <if test="searchText !=null">
  662. AND ( cat_name LIKE concat('%', #{searchText}, '%')
  663. or remarks LIKE concat('%', #{searchText}, '%'))
  664. </if>
  665. <if test="cpId != null">
  666. AND cp_id = #{cpId}
  667. </if>
  668. </where>
  669. </select>
  670. <!-- 查询商品系列-->
  671. <select id="getGoodsSeries" resultType="java.util.Map">
  672. SELECT
  673. series_id AS "seriesId",
  674. series_code AS "seriesCode",
  675. series_name AS "serieName",
  676. flg_valid AS "flgValid"
  677. FROM dkic_b.t_mst_goods_series
  678. <where>
  679. <if test="searchText !=null">
  680. AND ( series_name LIKE concat('%',my_ex.likequery(#{searchText}), '%')
  681. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  682. </if>
  683. <if test="cpId != null">
  684. AND cp_id = #{cpId}
  685. </if>
  686. </where>
  687. order by display_no asc
  688. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  689. limit #{end} offset #{start}
  690. </if>
  691. </select>
  692. <!-- 商品系列个数-->
  693. <select id="countGoodsSeries" resultType="java.lang.Long">
  694. SELECT
  695. count(1)
  696. FROM dkic_b.t_mst_goods_series
  697. <where>
  698. <if test="searchText !=null">
  699. AND ( series_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  700. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  701. </if>
  702. <if test="cpId != null">
  703. AND cp_id = #{cpId}
  704. </if>
  705. </where>
  706. </select>
  707. <!-- 获取计量单位-->
  708. <select id="getUnit" resultType="java.util.Map">
  709. SELECT
  710. unit_id AS "unitId",
  711. unit_code AS "unitCode",
  712. unit_name AS "unitName",
  713. decimal_places AS "decimalPlaces",
  714. flg_valid AS "flgValid"
  715. FROM dkic_b.t_mst_unit
  716. <where>
  717. <if test="searchText !=null">
  718. AND ( unit_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  719. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  720. </if>
  721. <if test="cpId != null">
  722. AND cp_id = #{cpId}
  723. </if>
  724. </where>
  725. order by display_no asc
  726. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  727. limit #{end} offset #{start}
  728. </if>
  729. </select>
  730. <!-- 获取计量单位个数-->
  731. <select id="countUnit" resultType="java.lang.Long">
  732. SELECT
  733. count(1)
  734. FROM dkic_b.t_mst_unit
  735. <where>
  736. <if test="searchText !=null">
  737. AND ( unit_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  738. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  739. </if>
  740. <if test="cpId != null">
  741. AND cp_id = #{cpId}
  742. </if>
  743. </where>
  744. </select>
  745. <!--获取仓库档案-->
  746. <select id="getWarehouseByPage" resultType="java.util.Map">
  747. SELECT
  748. wh_id AS "whId",
  749. wh_code AS "whCode",
  750. wh_name AS "whName",
  751. supervisor AS "supervisor",
  752. contact_phone AS "contactPhone",
  753. flg_valid AS "flgValid"
  754. FROM dkic_b.t_mst_warehouse
  755. <where>
  756. <if test="searchText !=null">
  757. AND ( wh_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  758. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  759. </if>
  760. <if test="cpId != null">
  761. AND cp_id = #{cpId}
  762. </if>
  763. </where>
  764. order by display_no asc
  765. <if test="pageSize != null and currentPage != null and pageSize != 0 and currentPage != 0">
  766. limit #{end} offset #{start}
  767. </if>
  768. </select>
  769. <!--获取仓库档案个数-->
  770. <select id="countWarehouseByPage" resultType="Long">
  771. SELECT
  772. count(1)
  773. FROM dkic_b.t_mst_warehouse
  774. <where>
  775. <if test="searchText !=null">
  776. AND ( wh_name LIKE concat('%', my_ex.likequery(#{searchText}), '%')
  777. or remarks LIKE concat('%', my_ex.likequery(#{searchText}), '%'))
  778. </if>
  779. <if test="cpId != null">
  780. AND cp_id = #{cpId}
  781. </if>
  782. </where>
  783. </select>
  784. <!-- 查询库存 -->
  785. <select id="getInventory" resultType="java.util.Map">
  786. select tpi.inv_id as "invId",
  787. tpi.sku_id as "skuId",
  788. tmgs.sku_code as "skuCode",
  789. tmgs.sku_name as "skuName",
  790. tmgs.sku_model as "skuModel",
  791. tmgs.brand_id as "brandId",
  792. tmgb.brand_name as "brandName",
  793. tmgs.category_id as "categoryId",
  794. tmgc.cat_name as "categoryName",
  795. tmgs.unit_id as "unitId",
  796. tmgu.unit_name as "unitName",
  797. tmgs.sub_unit_id as "subUnitId",
  798. tmgs.conversion_factor as "conversionFactor",
  799. tmgs.series_id as "seriesId",
  800. tmgseries.series_name as "seriesName",
  801. tmgs.sku_spec as "skuSpec",
  802. tmgs.price_purchase as "pricePurchase",
  803. tmgs.price_standard as "priceStandard",
  804. tmgs.price_wholesale as "priceWholesale",
  805. tmgs.price_limited as "priceLimited",
  806. tmgs.sku_images as "skuImages",
  807. tpi.non_std_code as "nonStdCode",
  808. tpi.inv_qty as "invQty",
  809. tpi.outing_qty as "outingQty",
  810. tpi.usable_qty as "usableQty",
  811. tpi.wh_id as "whId",
  812. tmw.wh_code as "whCode",
  813. tmw.wh_name as "whName",
  814. tpi.remarks
  815. from dkic_b.t_psi_inventory as tpi
  816. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  817. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  818. left join dkic_b.t_mst_goods_brand as tmgb on tmgs.brand_id = tmgb.brand_id
  819. left join dkic_b.t_mst_goods_category as tmgc on tmgs.category_id = tmgc.cat_id
  820. left join dkic_b.t_mst_goods_series as tmgseries on tmgs.series_id = tmgseries.series_id
  821. left join dkic_b.t_mst_unit as tmgu on tmgs.unit_id = tmgu.unit_id
  822. where tpi.flg_valid
  823. AND tpi.cp_id = #{cpId}
  824. <if test="skuId != null">
  825. AND tpi.sku_id = #{skuId} ::uuid
  826. </if>
  827. <if test="nonStdCode != null">
  828. AND tpi.non_std_code = #{nonStdCode}
  829. </if>
  830. <if test="skuCode != null">
  831. AND tmgs.sku_code LIKE concat('%',my_ex.likequery(#{skuCode}),'%')
  832. </if>
  833. <if test="skuName != null">
  834. AND tmgs.sku_name LIKE concat('%',my_ex.likequery(#{skuName}),'%')
  835. </if>
  836. <if test="whName != null">
  837. AND tmgs.wh_name LIKE concat('%',my_ex.likequery(#{whName}),'%')
  838. </if>
  839. </select>
  840. <!-- 查询库存个数 -->
  841. <select id="getInventoryCountByPage" resultType="Long">
  842. SELECT
  843. count(1)
  844. from dkic_b.t_psi_inventory as tpi
  845. inner join dkic_b.t_mst_warehouse as tmw on tmw.wh_id = tpi.wh_id
  846. inner join dkic_b.t_mst_goods_sku as tmgs on tmgs.sku_id = tpi.sku_id
  847. where tpi.flg_valid
  848. AND tpi.cp_id = #{cpId}
  849. <if test="skuId != null">
  850. AND tpi.sku_id = #{skuId} ::uuid
  851. </if>
  852. <if test="nonStdCode != null">
  853. AND tpi.non_std_code = #{nonStdCode}
  854. </if>
  855. <if test="skuCode != null">
  856. AND tmgs.sku_code = #{skuCode}
  857. </if>
  858. <if test="skuName != null">
  859. AND tmgs.sku_name = #{skuName}
  860. </if>
  861. <if test="whName != null">
  862. AND tmgs.wh_name = #{whName}
  863. </if>
  864. </select>
  865. <!-- 获取销售渠道-->
  866. <select id="getSaleChannel" resultType="java.util.Map">
  867. SELECT
  868. channel_id AS "channelId",
  869. channel_id AS "id",
  870. channel_code AS "channelCode",
  871. channel_name AS "channelName"
  872. FROM dkic_b.t_mst_sale_channel
  873. <where>
  874. <if test="cpId != null">
  875. AND cp_id = #{cpId}
  876. </if>
  877. </where>
  878. </select>
  879. <!--获取员工-->
  880. <select id="getStaff" resultType="java.util.Map">
  881. SELECT
  882. staff_id AS "staffId",
  883. staff_id AS "id",
  884. staff_code AS "staffCode",
  885. staff_name AS "staffName"
  886. FROM dkic_b.t_mst_staff
  887. <where>
  888. <if test="cpId != null">
  889. AND cp_id = #{cpId}
  890. </if>
  891. </where>
  892. </select>
  893. <!--获取仓库档案-->
  894. </mapper>