Titem.java 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353
  1. /**
  2. *
  3. */
  4. package openapi.restcontroller.wechatapp.titem;
  5. import net.sf.json.JSONArray;
  6. import net.sf.json.JSONObject;
  7. import openapi.base.Controller;
  8. import openapi.base.SQLFactory;
  9. import openapi.base.data.Row;
  10. import openapi.base.data.Rows;
  11. import openapi.base.data.RowsMap;
  12. import openapi.base.data.RowsPool.RowsPool;
  13. import openapi.base.data.db.DBConnect;
  14. import p2.pao.PaoRemote;
  15. import p2.pao.PaoSetRemote;
  16. import p2.util.P2Exception;
  17. import titem.icinvbalMsg;
  18. import titem.titem;
  19. import java.sql.SQLData;
  20. import java.util.Arrays;
  21. import java.util.HashMap;
  22. /**
  23. * @author Administrator
  24. *
  25. */
  26. public class Titem extends Controller {
  27. /**
  28. * @param content
  29. */
  30. public Titem(JSONObject content) {
  31. super(content);
  32. }
  33. public String query() throws Exception {
  34. /**
  35. * 创建数据库连接
  36. */
  37. DBConnect drpConnect = new DBConnect();
  38. /**
  39. *排序条件设置
  40. */
  41. String[] sortmsg = {"t1.fitemno", "t1.fitemname", "t1.fspec"};
  42. String sort = sortmsg[0];
  43. if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
  44. sort = content.getString("sort");
  45. }
  46. /**
  47. * 过滤条件设置
  48. */
  49. String where = " 1=1 ";
  50. if (content.containsKey("where")) {
  51. JSONObject whereObject = content.getJSONObject("where");
  52. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  53. where = where + " and(t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fitemno='" + whereObject.getString("condition") + "' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  54. }
  55. if (whereObject.containsKey("fitemno") && !"".equals(whereObject.getString("fitemno"))) {
  56. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  57. }
  58. if (whereObject.containsKey("fspec") && !"".equals(whereObject.getString("fspec"))) {
  59. where = where + " and t1.fspec ='" + whereObject.getString("fspec") + "'";
  60. }
  61. if (whereObject.containsKey("fsaleclsnum") && !"".equals(whereObject.getString("fsaleclsnum"))) {
  62. SQLFactory flongsaleslsFactory = new SQLFactory(this, "营销类别全路径查询");
  63. flongsaleslsFactory.addParameter("fsaleclsnum", whereObject.getString("fsaleclsnum"));
  64. flongsaleslsFactory.addParameter("siteid", siteid);
  65. Rows flongsaleslsRows = drpConnect.runSqlQuery(flongsaleslsFactory.getSQL());
  66. if (flongsaleslsRows.isEmpty()) {
  67. where = where + " and 1=2";
  68. } else {
  69. //where = where + " and t1.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%'";
  70. where = where + " and exists(select *from titem_saleclsnum where titem_saleclsnum.siteid=t1.siteid and titem_saleclsnum.fitemno=t1.fitemno and titem_saleclsnum.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%') ";
  71. }
  72. }
  73. if (whereObject.containsKey("fiscollection") && !"".equals(whereObject.getString("fiscollection"))) {
  74. where = where + " and isnull(t4.fiscollection,0) ='" + whereObject.getString("fiscollection") + "'";
  75. }
  76. if (whereObject.containsKey("fiscustomized") && !"".equals(whereObject.getString("fiscustomized"))) {
  77. where = where + " and t1.fiscustomized ='" + whereObject.getString("fiscustomized") + "'";
  78. }
  79. if (whereObject.containsKey("fiswuliao") && !"".equals(whereObject.getString("fiswuliao"))) {
  80. where = where + " and t1.fiswuliao ='" + whereObject.getString("fiswuliao") + "'";
  81. }
  82. if (whereObject.containsKey("fieldname") && !"".equals(whereObject.getString("fieldname"))) {
  83. where = where + " and t1.fieldname ='" + whereObject.getString("fieldname") + "'";
  84. }
  85. if (whereObject.containsKey("fbrand") && !"".equals(whereObject.getString("fbrand"))) {
  86. where = where + " and t1.fbrand ='" + whereObject.getString("fbrand") + "'";
  87. }
  88. if (whereObject.containsKey("fistool") && !"".equals(whereObject.getString("fistool"))) {
  89. where = where + " and t1.fistool ='" + whereObject.getString("fistool") + "'";
  90. }
  91. if (whereObject.containsKey("fvalue8") && whereObject.getBoolean("fvalue8")) {
  92. //如果是中线碟阀
  93. where = where + " and t1.fvalue8=1";
  94. }
  95. if (whereObject.containsKey("fvalue7") && !"".equals(whereObject.getString("fvalue7"))) {
  96. where = where + " and t1.fvalue7 ='" + whereObject.getString("fvalue7") + "'";
  97. }
  98. if (whereObject.containsKey("fvalue6") && !"".equals(whereObject.getString("fvalue6"))) {
  99. where = where + " and t1.fvalue6 ='" + whereObject.getString("fvalue6") + "'";
  100. }
  101. if (whereObject.containsKey("fvalue5") && !"".equals(whereObject.getString("fvalue5"))) {
  102. where = where + " and t1.fvalue5 ='" + whereObject.getString("fvalue5") + "'";
  103. }
  104. if (whereObject.containsKey("fvalue4") && !"".equals(whereObject.getString("fvalue4"))) {
  105. where = where + " and t1.fvalue4 ='" + whereObject.getString("fvalue4") + "'";
  106. }
  107. if (whereObject.containsKey("fvalue3") && !"".equals(whereObject.getString("fvalue3"))) {
  108. where = where + " and t1.fvalue3 ='" + whereObject.getString("fvalue3") + "'";
  109. }
  110. if (whereObject.containsKey("fvalue2") && !"".equals(whereObject.getString("fvalue2"))) {
  111. where = where + " and t1.fvalue2 ='" + whereObject.getString("fvalue2") + "'";
  112. }
  113. if (whereObject.containsKey("fvalue1") && !"".equals(whereObject.getString("fvalue1"))) {
  114. where = where + " and t1.fvalue1 ='" + whereObject.getString("fvalue1") + "'";
  115. }
  116. }
  117. /**
  118. * SQL货品档案查询参数设置并查询
  119. */
  120. SQLFactory factory = new SQLFactory(this, "货品档案列表查询", pageSize, pageNumber, sort);
  121. factory.addParameter("fagentnum", fagentnum);
  122. factory.addParameter("siteid", siteid);
  123. factory.addParameter_SQL("where", where);
  124. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  125. /**
  126. * 获取品号批查条件
  127. */
  128. String itemwhere = rows.getInWhere("fitemno");
  129. String[] itemarray = rows.toArray("fitemno");
  130. /**
  131. *商品图片查询参数设置,并将结果存放置map
  132. */
  133. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, itemarray);
  134. /**
  135. *商品产品样册查询参数设置,并将结果存放置map
  136. */
  137. RowsMap samplebookmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_SAMPLEBOOK, itemarray);
  138. /**
  139. *商品说明书查询参数设置,并将结果存放置map
  140. */
  141. RowsMap instructionsmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTRUCTIONS, itemarray);
  142. /**
  143. *商品安装教程查询参数设置,并将结果存放置map
  144. */
  145. RowsMap installationtutorialmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTALLATIONTUTORIAL, itemarray);
  146. /**
  147. * 商品营销类别
  148. */
  149. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  150. saleclsnumsqlFactory.addParameter("siteid", siteid);
  151. saleclsnumsqlFactory.addParameter_in("fitemno", itemarray);
  152. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  153. /**
  154. *更新即时库存
  155. */
  156. new icinvbalMsg().caculate(siteid, rows.toArray("fitemno"), false);
  157. /**
  158. * 获取商品相关信息
  159. */
  160. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + itemwhere + " and siteid='" + siteid + "'");
  161. HashMap<String, PaoRemote> itemmap = getPaoMap(titemset, "fitemno");
  162. /**
  163. * 遍历货品档案,设置商品信息
  164. */
  165. for (Row itemrow : rows) {
  166. String fitemno = itemrow.getString("fitemno");
  167. titem titem = (titem) itemmap.get(fitemno);
  168. double foldprice = titem.getCardPriceByAagentnum(fagentnum);
  169. double fprice = titem.getAgentSalePrice(foldprice, fagentnum);
  170. String fsaorderstockstatus = titem.getString("fsaorderstockstatus");
  171. double ficqty = titem.getDouble("ficqty");
  172. //库存状态
  173. itemrow.put("fsaorderstockstatus", fsaorderstockstatus);
  174. //库存数量
  175. itemrow.put("ficqty", ficqty);
  176. //牌价
  177. itemrow.put("foldprice", foldprice);
  178. //销售价
  179. itemrow.put("fprice", fprice);
  180. //图片
  181. itemrow.put("pics", picmap.get(fitemno));
  182. //产品样册
  183. itemrow.put("samplebook", samplebookmap.get(fitemno));
  184. //产品说明书
  185. itemrow.put("instructions", instructionsmap.get(fitemno));
  186. //安装教程
  187. itemrow.put("installationtutorial", installationtutorialmap.get(fitemno));
  188. //营销分类
  189. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  190. }
  191. titemset.close();
  192. return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
  193. }
  194. public String query_tool() throws Exception {
  195. /**
  196. * 创建数据库连接
  197. */
  198. DBConnect drpConnect = new DBConnect();
  199. /**
  200. *排序条件设置
  201. */
  202. String[] sortmsg = {"t1.fitemno", "t1.fitemname", "t1.fspec"};
  203. String sort = sortmsg[0];
  204. if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
  205. sort = content.getString("sort");
  206. }
  207. /**
  208. * 过滤条件设置
  209. */
  210. String where = " t1.fistool=1 ";
  211. if (content.containsKey("where")) {
  212. JSONObject whereObject = content.getJSONObject("where");
  213. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  214. //where = where + " and(t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  215. where = where + " and(t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fitemno='" + whereObject.getString("condition") + "' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  216. }
  217. if (whereObject.containsKey("fspec") && !"".equals(whereObject.getString("fspec"))) {
  218. where = where + " and t1.fspec ='" + whereObject.getString("fspec") + "'";
  219. }
  220. if (whereObject.containsKey("fitemno") && !"".equals(whereObject.getString("fitemno"))) {
  221. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  222. }
  223. if (whereObject.containsKey("fproductstandard") && !"".equals(whereObject.getString("fproductstandard"))) {
  224. where = where + " and t1.fproductstandard ='" + whereObject.getString("fproductstandard") + "'";
  225. }
  226. if (whereObject.containsKey("fsaleclsnum") && !"".equals(whereObject.getString("fsaleclsnum"))) {
  227. SQLFactory flongsaleslsFactory = new SQLFactory(this, "营销类别全路径查询");
  228. flongsaleslsFactory.addParameter("fsaleclsnum", whereObject.getString("fsaleclsnum"));
  229. flongsaleslsFactory.addParameter("siteid", siteid);
  230. Rows flongsaleslsRows = drpConnect.runSqlQuery(flongsaleslsFactory.getSQL());
  231. if (flongsaleslsRows.isEmpty()) {
  232. where = where + " and 1=2";
  233. } else {
  234. // where = where + " and t1.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%'";
  235. where = where + " and exists(select *from titem_saleclsnum where titem_saleclsnum.siteid=t1.siteid and titem_saleclsnum.fitemno=t1.fitemno and titem_saleclsnum.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%') ";
  236. }
  237. }
  238. if (whereObject.containsKey("fieldname") && !"".equals(whereObject.getString("fieldname"))) {
  239. where = where + " and t1.fieldname ='" + whereObject.getString("fieldname") + "'";
  240. }
  241. if (whereObject.containsKey("fbrand") && !"".equals(whereObject.getString("fbrand"))) {
  242. where = where + " and t1.fbrand ='" + whereObject.getString("fbrand") + "'";
  243. }
  244. }
  245. /**
  246. * SQL货品档案查询参数设置并查询
  247. */
  248. SQLFactory factory = new SQLFactory(this, "工具档案列表查询", pageSize, pageNumber, sort);
  249. factory.addParameter("fagentnum", fagentnum);
  250. factory.addParameter("siteid", siteid);
  251. factory.addParameter_SQL("where", where);
  252. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  253. /**
  254. * 获取品号批查条件
  255. */
  256. String itemwhere = rows.getInWhere("fitemno");
  257. String[] itemarray = rows.toArray("fitemno");
  258. /**
  259. *商品图片查询参数设置,并将结果存放置map
  260. */
  261. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, itemarray);
  262. /**
  263. *商品产品样册查询参数设置,并将结果存放置map
  264. */
  265. RowsMap samplebookmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_SAMPLEBOOK, itemarray);
  266. /**
  267. *商品说明书查询参数设置,并将结果存放置map
  268. */
  269. RowsMap instructionsmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTRUCTIONS, itemarray);
  270. /**
  271. *商品安装教程查询参数设置,并将结果存放置map
  272. */
  273. RowsMap installationtutorialmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTALLATIONTUTORIAL, itemarray);
  274. /**
  275. * 商品营销类别
  276. */
  277. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  278. saleclsnumsqlFactory.addParameter("siteid", siteid);
  279. saleclsnumsqlFactory.addParameter_in("fitemno", itemarray);
  280. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  281. /**
  282. *更新即时库存
  283. */
  284. new icinvbalMsg().caculate(siteid, rows.toArray("fitemno"), false);
  285. /**
  286. * 获取商品相关信息
  287. */
  288. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + itemwhere + " and siteid='" + siteid + "'");
  289. HashMap<String, PaoRemote> itemmap = getPaoMap(titemset, "fitemno");
  290. /**
  291. * 遍历货品档案,设置商品信息
  292. */
  293. for (Row itemrow : rows) {
  294. String fitemno = itemrow.getString("fitemno");
  295. titem titem = (titem) itemmap.get(fitemno);
  296. double foldprice = titem.getCardPriceByAagentnum(fagentnum);
  297. double fprice = titem.getAgentSalePrice(foldprice, fagentnum);
  298. String fsaorderstockstatus = titem.getString("fsaorderstockstatus");
  299. double ficqty = titem.getDouble("ficqty");
  300. //库存状态
  301. itemrow.put("fsaorderstockstatus", fsaorderstockstatus);
  302. itemrow.put("ficqty", ficqty);
  303. //牌价
  304. itemrow.put("foldprice", foldprice);
  305. //销售价
  306. itemrow.put("fprice", fprice);
  307. //图片
  308. itemrow.put("pics", picmap.get(fitemno));
  309. //产品样册
  310. itemrow.put("samplebook", samplebookmap.get(fitemno));
  311. //产品说明书
  312. itemrow.put("instructions", instructionsmap.get(fitemno));
  313. //安装教程
  314. itemrow.put("installationtutorial", installationtutorialmap.get(fitemno));
  315. //营销分类
  316. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  317. }
  318. titemset.close();
  319. return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
  320. }
  321. public String query_toolsaler() throws Exception {
  322. /**
  323. * 创建数据库连接
  324. */
  325. DBConnect drpConnect = new DBConnect();
  326. /**
  327. *排序条件设置
  328. */
  329. String[] sortmsg = {"t1.fitemno", "t1.fitemname", "t1.fspec"};
  330. String sort = sortmsg[0];
  331. if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
  332. sort = content.getString("sort");
  333. }
  334. /**
  335. * 过滤条件设置
  336. */
  337. String where = " t1.fistool=1 ";
  338. if (content.containsKey("where")) {
  339. JSONObject whereObject = content.getJSONObject("where");
  340. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  341. // where = where + " and(t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  342. where = where + " and(t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fitemno='" + whereObject.getString("condition") + "' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  343. }
  344. if (whereObject.containsKey("fspec") && !"".equals(whereObject.getString("fspec"))) {
  345. where = where + " and t1.fspec ='" + whereObject.getString("fspec") + "'";
  346. }
  347. if (whereObject.containsKey("fitemno") && !"".equals(whereObject.getString("fitemno"))) {
  348. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  349. }
  350. if (whereObject.containsKey("fproductstandard") && !"".equals(whereObject.getString("fproductstandard"))) {
  351. where = where + " and t1.fproductstandard ='" + whereObject.getString("fproductstandard") + "'";
  352. }
  353. if (whereObject.containsKey("fsaleclsnum") && !"".equals(whereObject.getString("fsaleclsnum"))) {
  354. SQLFactory flongsaleslsFactory = new SQLFactory(this, "营销类别全路径查询");
  355. flongsaleslsFactory.addParameter("fsaleclsnum", whereObject.getString("fsaleclsnum"));
  356. flongsaleslsFactory.addParameter("siteid", siteid);
  357. Rows flongsaleslsRows = drpConnect.runSqlQuery(flongsaleslsFactory.getSQL());
  358. if (flongsaleslsRows.isEmpty()) {
  359. where = where + " and 1=2";
  360. } else {
  361. //where = where + " and t1.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%'";
  362. where = where + " and exists(select *from titem_saleclsnum where titem_saleclsnum.siteid=t1.siteid and titem_saleclsnum.fitemno=t1.fitemno and titem_saleclsnum.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%') ";
  363. }
  364. }
  365. if (whereObject.containsKey("fieldname") && !"".equals(whereObject.getString("fieldname"))) {
  366. where = where + " and t1.fieldname ='" + whereObject.getString("fieldname") + "'";
  367. }
  368. if (whereObject.containsKey("fbrand") && !"".equals(whereObject.getString("fbrand"))) {
  369. where = where + " and t1.fbrand ='" + whereObject.getString("fbrand") + "'";
  370. }
  371. }
  372. /**
  373. * SQL货品档案查询参数设置并查询
  374. */
  375. SQLFactory factory = new SQLFactory(this, "工具档案列表查询_业务员", pageSize, pageNumber, sort);
  376. factory.addParameter("siteid", siteid);
  377. factory.addParameter_SQL("where", where);
  378. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  379. /**
  380. * 获取品号批查条件
  381. */
  382. String itemwhere = rows.getInWhere("fitemno");
  383. String[] itemarray = rows.toArray("fitemno");
  384. /**
  385. *商品图片查询参数设置,并将结果存放置map
  386. */
  387. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, itemarray);
  388. /**
  389. *商品产品样册查询参数设置,并将结果存放置map
  390. */
  391. RowsMap samplebookmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_SAMPLEBOOK, itemarray);
  392. /**
  393. *商品说明书查询参数设置,并将结果存放置map
  394. */
  395. RowsMap instructionsmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTRUCTIONS, itemarray);
  396. /**
  397. *商品安装教程查询参数设置,并将结果存放置map
  398. */
  399. RowsMap installationtutorialmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTALLATIONTUTORIAL, itemarray);
  400. /**
  401. * 商品营销类别
  402. */
  403. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  404. saleclsnumsqlFactory.addParameter("siteid", siteid);
  405. saleclsnumsqlFactory.addParameter_in("fitemno", itemarray);
  406. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  407. /**
  408. *更新即时库存
  409. */
  410. new icinvbalMsg().caculate(siteid, rows.toArray("fitemno"), false);
  411. /**
  412. * 获取商品相关信息
  413. */
  414. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + itemwhere + " and siteid='" + siteid + "'");
  415. HashMap<String, PaoRemote> itemmap = getPaoMap(titemset, "fitemno");
  416. /**
  417. * 遍历货品档案,设置商品信息
  418. */
  419. for (Row itemrow : rows) {
  420. String fitemno = itemrow.getString("fitemno");
  421. titem titem = (titem) itemmap.get(fitemno);
  422. double foldprice = titem.getCardPriceByGrade("1");
  423. String fsaorderstockstatus = titem.getString("fsaorderstockstatus");
  424. double ficqty = titem.getDouble("ficqty");
  425. //库存状态
  426. itemrow.put("fsaorderstockstatus", fsaorderstockstatus);
  427. itemrow.put("ficqty", ficqty);
  428. //牌价
  429. itemrow.put("foldprice", foldprice);
  430. //销售价
  431. itemrow.put("fprice", foldprice);
  432. //图片
  433. itemrow.put("pics", picmap.get(fitemno));
  434. //产品样册
  435. itemrow.put("samplebook", samplebookmap.get(fitemno));
  436. //产品说明书
  437. itemrow.put("instructions", instructionsmap.get(fitemno));
  438. //安装教程
  439. itemrow.put("installationtutorial", installationtutorialmap.get(fitemno));
  440. //营销分类
  441. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  442. }
  443. titemset.close();
  444. return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
  445. }
  446. /**
  447. * 订单商品添加查询
  448. * @return
  449. */
  450. public String query_order() throws Exception {
  451. /**
  452. * 创建数据库连接
  453. */
  454. DBConnect drpConnect = new DBConnect();
  455. /**
  456. *排序条件设置
  457. */
  458. String[] sortmsg = {"t6.sequence,t5.fgroupnum,t5.frownum"};
  459. String sort = sortmsg[0];
  460. if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
  461. sort = content.getString("sort");
  462. }
  463. /**
  464. * 过滤条件设置
  465. */
  466. String where = " 1=1 ";
  467. if (content.containsKey("where")) {
  468. JSONObject whereObject = content.getJSONObject("where");
  469. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  470. where = where + " and(t1.fitemno like'%" + whereObject.getString("condition") + "%' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  471. }
  472. if (whereObject.containsKey("fitemno") && !"".equals(whereObject.getString("fitemno"))) {
  473. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  474. }
  475. if (whereObject.containsKey("fspec") && !"".equals(whereObject.getString("fspec"))) {
  476. where = where + " and t1.fspec ='" + whereObject.getString("fspec") + "'";
  477. }
  478. if (whereObject.containsKey("fsaleclsnum") && !"".equals(whereObject.getString("fsaleclsnum"))) {
  479. SQLFactory flongsaleslsFactory = new SQLFactory(this, "营销类别全路径查询");
  480. flongsaleslsFactory.addParameter("fsaleclsnum", whereObject.getString("fsaleclsnum"));
  481. flongsaleslsFactory.addParameter("siteid", siteid);
  482. Rows flongsaleslsRows = drpConnect.runSqlQuery(flongsaleslsFactory.getSQL());
  483. if (flongsaleslsRows.isEmpty()) {
  484. where = where + " and 1=2";
  485. } else {
  486. //where = where + " and t1.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%'";
  487. where = where + " and exists(select *from titem_saleclsnum where titem_saleclsnum.siteid=t1.siteid and titem_saleclsnum.fitemno=t1.fitemno and titem_saleclsnum.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%') ";
  488. }
  489. }
  490. if (whereObject.containsKey("fiscollection") && !"".equals(whereObject.getString("fiscollection"))) {
  491. where = where + " and isnull(t4.fiscollection,0) ='" + whereObject.getString("fiscollection") + "'";
  492. }
  493. if (whereObject.containsKey("fiscustomized") && !"".equals(whereObject.getString("fiscustomized"))) {
  494. where = where + " and t1.fiscustomized ='" + whereObject.getString("fiscustomized") + "'";
  495. }
  496. if (whereObject.containsKey("fiswuliao") && !"".equals(whereObject.getString("fiswuliao"))) {
  497. where = where + " and t1.fiswuliao ='" + whereObject.getString("fiswuliao") + "'";
  498. }
  499. if (whereObject.containsKey("fieldname") && !"".equals(whereObject.getString("fieldname"))) {
  500. where = where + " and t1.fieldname ='" + whereObject.getString("fieldname") + "'";
  501. }
  502. if (whereObject.containsKey("fbrand") && !"".equals(whereObject.getString("fbrand"))) {
  503. where = where + " and t1.fbrand ='" + whereObject.getString("fbrand") + "'";
  504. }
  505. if (whereObject.containsKey("fistool") && !"".equals(whereObject.getString("fistool"))) {
  506. where = where + " and t1.fistool ='" + whereObject.getString("fistool") + "'";
  507. }
  508. }
  509. /**
  510. * SQL货品档案查询参数设置并查询
  511. */
  512. SQLFactory factory = new SQLFactory(this, "货品档案列表查询2", pageSize, pageNumber, sort);
  513. factory.addParameter("fagentnum", fagentnum);
  514. factory.addParameter("siteid", siteid);
  515. factory.addParameter_SQL("where", where);
  516. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  517. /**
  518. * 获取品号批查条件
  519. */
  520. String itemwhere = rows.getInWhere("fitemno");
  521. /**
  522. *商品图片查询参数设置,并将结果存放置map
  523. */
  524. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, rows.toArray("fitemno"));
  525. /**
  526. * 商品营销类别
  527. */
  528. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  529. saleclsnumsqlFactory.addParameter("siteid", siteid);
  530. saleclsnumsqlFactory.addParameter_in("fitemno", rows.toArray("fitemno"));
  531. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  532. /**
  533. *更新即时库存
  534. */
  535. new icinvbalMsg().caculate(siteid, rows.toArray("fitemno"), false);
  536. /**
  537. * 获取商品相关信息
  538. */
  539. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + itemwhere + " and siteid='" + siteid + "'");
  540. HashMap<String, PaoRemote> itemmap = getPaoMap(titemset, "fitemno");
  541. /**
  542. * 遍历货品档案,设置商品信息
  543. */
  544. for (Row itemrow : rows) {
  545. String fitemno = itemrow.getString("fitemno");
  546. titem titem = (titem) itemmap.get(fitemno);
  547. double foldprice = titem.getCardPriceByGrade("1");
  548. String fsaorderstockstatus = titem.getString("fsaorderstockstatus");
  549. double ficqty = titem.getDouble("ficqty");
  550. //库存状态
  551. itemrow.put("fsaorderstockstatus", fsaorderstockstatus);
  552. itemrow.put("ficqty", ficqty);
  553. //牌价
  554. itemrow.put("foldprice", foldprice);
  555. //销售价
  556. itemrow.put("fprice", foldprice);
  557. //图片
  558. itemrow.put("pics", picmap.get(fitemno));
  559. //营销分类
  560. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  561. }
  562. titemset.close();
  563. return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
  564. }
  565. /**
  566. * 简单商品查询
  567. * @return
  568. */
  569. public String query_simpleList() throws Exception {
  570. /**
  571. * 创建数据库连接
  572. */
  573. DBConnect drpConnect = new DBConnect();
  574. /**
  575. *排序条件设置
  576. */
  577. String[] sortmsg = {"t1.fitemno", "t1.fitemname", "t1.fspec"};
  578. String sort = sortmsg[0];
  579. if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
  580. sort = content.getString("sort");
  581. }
  582. /**
  583. * 是否包含价格
  584. */
  585. boolean withprice = content.containsKey("withprice") && content.getString("withprice").equals("1");
  586. /**
  587. * 过滤条件设置
  588. */
  589. String where = " 1=1 ";
  590. if (content.containsKey("where")) {
  591. JSONObject whereObject = content.getJSONObject("where");
  592. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  593. where = where + " and(t1.fitemno like'%" + whereObject.getString("condition") + "%' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  594. }
  595. if (whereObject.containsKey("fspec") && !"".equals(whereObject.getString("fspec"))) {
  596. where = where + " and t1.fspec ='" + whereObject.getString("fspec") + "'";
  597. }
  598. if (whereObject.containsKey("fitemno") && !"".equals(whereObject.getString("fitemno"))) {
  599. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  600. }
  601. if (whereObject.containsKey("fsaleclsnum") && !"".equals(whereObject.getString("fsaleclsnum"))) {
  602. SQLFactory flongsaleslsFactory = new SQLFactory(this, "营销类别全路径查询");
  603. flongsaleslsFactory.addParameter("fsaleclsnum", whereObject.getString("fsaleclsnum"));
  604. flongsaleslsFactory.addParameter("siteid", siteid);
  605. Rows flongsaleslsRows = drpConnect.runSqlQuery(flongsaleslsFactory.getSQL());
  606. if (flongsaleslsRows.isEmpty()) {
  607. where = where + " and 1=2";
  608. } else {
  609. //where = where + " and t1.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%'";
  610. where = where + " and exists(select *from titem_saleclsnum where titem_saleclsnum.siteid=t1.siteid and titem_saleclsnum.fitemno=t1.fitemno and titem_saleclsnum.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%') ";
  611. }
  612. }
  613. if (whereObject.containsKey("fiscollection") && !"".equals(whereObject.getString("fiscollection"))) {
  614. where = where + " and isnull(t4.fiscollection,0) ='" + whereObject.getString("fiscollection") + "'";
  615. }
  616. if (whereObject.containsKey("fiscustomized") && !"".equals(whereObject.getString("fiscustomized"))) {
  617. where = where + " and t1.fiscustomized ='" + whereObject.getString("fiscustomized") + "'";
  618. }
  619. if (whereObject.containsKey("fiswuliao") && !"".equals(whereObject.getString("fiswuliao"))) {
  620. where = where + " and t1.fiswuliao ='" + whereObject.getString("fiswuliao") + "'";
  621. }
  622. if (whereObject.containsKey("fieldname") && !"".equals(whereObject.getString("fieldname"))) {
  623. where = where + " and t1.fieldname ='" + whereObject.getString("fieldname") + "'";
  624. }
  625. if (whereObject.containsKey("fbrand") && !"".equals(whereObject.getString("fbrand"))) {
  626. where = where + " and t1.fbrand ='" + whereObject.getString("fbrand") + "'";
  627. }
  628. if (whereObject.containsKey("fistool") && !"".equals(whereObject.getString("fistool"))) {
  629. where = where + " and t1.fistool ='" + whereObject.getString("fistool") + "'";
  630. }
  631. }
  632. /**
  633. * SQL货品档案查询参数设置并查询
  634. */
  635. SQLFactory factory = new SQLFactory(this, "简单货品档案列表查询", pageSize, pageNumber, sort);
  636. factory.addParameter("siteid", siteid);
  637. factory.addParameter_SQL("where", where);
  638. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  639. /**
  640. *商品图片查询参数设置,并将结果存放置map
  641. */
  642. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, rows.toArray("fitemno"));
  643. /**
  644. * 商品营销类别
  645. */
  646. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  647. saleclsnumsqlFactory.addParameter("siteid", siteid);
  648. saleclsnumsqlFactory.addParameter_in("fitemno", rows.toArray("fitemno"));
  649. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  650. HashMap<String, PaoRemote> itemmap = null;
  651. if (withprice) {
  652. /**
  653. * 获取商品相关信息
  654. */
  655. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + rows.getInWhere("fitemno") + " and siteid='" + siteid + "'");
  656. itemmap = getPaoMap(titemset, "fitemno");
  657. }
  658. /**
  659. * 遍历货品档案,设置商品信息
  660. */
  661. for (Row itemrow : rows) {
  662. String fitemno = itemrow.getString("fitemno");
  663. //图片
  664. itemrow.put("pics", picmap.get(fitemno));
  665. if (withprice) {
  666. titem titem = (titem) itemmap.get(fitemno);
  667. if (content.containsKey("fprojectnum") && !content.getString("fprojectnum").equals("")) {
  668. titem.fprojectnum = content.getString("fprojectnum");
  669. }
  670. double foldprice = titem.getCardPriceByAagentnum(fagentnum);
  671. double fprice = titem.getAgentSalePrice(foldprice, fagentnum);
  672. //牌价
  673. itemrow.put("foldprice", foldprice);
  674. //销售价
  675. itemrow.put("fprice", fprice);
  676. //营销分类
  677. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  678. }
  679. }
  680. return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
  681. }
  682. /**
  683. * 项目订单商品选择
  684. * @return
  685. */
  686. public String query_projectitemList() throws Exception {
  687. /**
  688. * 创建数据库连接
  689. */
  690. DBConnect drpConnect = new DBConnect();
  691. /**
  692. *排序条件设置
  693. */
  694. String[] sortmsg = {"t1.fitemno", "t1.fitemname", "t1.fspec"};
  695. String sort = sortmsg[0];
  696. if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
  697. sort = content.getString("sort");
  698. }
  699. /**
  700. * 是否包含价格
  701. */
  702. boolean withprice = content.containsKey("withprice") && content.getString("withprice").equals("1");
  703. String fprojectnum = content.getString("fprojectnum");//项目编号
  704. /**
  705. * 过滤条件设置
  706. */
  707. String where = " 1=1 ";
  708. if (content.containsKey("where")) {
  709. JSONObject whereObject = content.getJSONObject("where");
  710. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  711. where = where + " and(t1.fitemno like'%" + whereObject.getString("condition") + "%' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  712. }
  713. if (whereObject.containsKey("fspec") && !"".equals(whereObject.getString("fspec"))) {
  714. where = where + " and t1.fspec ='" + whereObject.getString("fspec") + "'";
  715. }
  716. if (whereObject.containsKey("fitemno") && !"".equals(whereObject.getString("fitemno"))) {
  717. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  718. }
  719. if (whereObject.containsKey("fsaleclsnum") && !"".equals(whereObject.getString("fsaleclsnum"))) {
  720. SQLFactory flongsaleslsFactory = new SQLFactory(this, "营销类别全路径查询");
  721. flongsaleslsFactory.addParameter("fsaleclsnum", whereObject.getString("fsaleclsnum"));
  722. flongsaleslsFactory.addParameter("siteid", siteid);
  723. Rows flongsaleslsRows = drpConnect.runSqlQuery(flongsaleslsFactory.getSQL());
  724. if (flongsaleslsRows.isEmpty()) {
  725. where = where + " and 1=2";
  726. } else {
  727. //where = where + " and t1.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%'";
  728. where = where + " and exists(select *from titem_saleclsnum where titem_saleclsnum.siteid=t1.siteid and titem_saleclsnum.fitemno=t1.fitemno and titem_saleclsnum.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%') ";
  729. }
  730. }
  731. if (whereObject.containsKey("fiscollection") && !"".equals(whereObject.getString("fiscollection"))) {
  732. where = where + " and isnull(t4.fiscollection,0) ='" + whereObject.getString("fiscollection") + "'";
  733. }
  734. if (whereObject.containsKey("fiscustomized") && !"".equals(whereObject.getString("fiscustomized"))) {
  735. where = where + " and t1.fiscustomized ='" + whereObject.getString("fiscustomized") + "'";
  736. }
  737. if (whereObject.containsKey("fiswuliao") && !"".equals(whereObject.getString("fiswuliao"))) {
  738. where = where + " and t1.fiswuliao ='" + whereObject.getString("fiswuliao") + "'";
  739. }
  740. if (whereObject.containsKey("fieldname") && !"".equals(whereObject.getString("fieldname"))) {
  741. where = where + " and t1.fieldname ='" + whereObject.getString("fieldname") + "'";
  742. }
  743. if (whereObject.containsKey("fbrand") && !"".equals(whereObject.getString("fbrand"))) {
  744. where = where + " and t1.fbrand ='" + whereObject.getString("fbrand") + "'";
  745. }
  746. if (whereObject.containsKey("fistool") && !"".equals(whereObject.getString("fistool"))) {
  747. where = where + " and t1.fistool ='" + whereObject.getString("fistool") + "'";
  748. }
  749. }
  750. /**
  751. * SQL货品档案查询参数设置并查询
  752. */
  753. SQLFactory factory = new SQLFactory(this, "项目订单货品档案列表查询", pageSize, pageNumber, sort);
  754. factory.addParameter("fprojectnum", fprojectnum);
  755. factory.addParameter("siteid", siteid);
  756. factory.addParameter_SQL("where", where);
  757. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  758. /**
  759. *商品图片查询参数设置,并将结果存放置map
  760. */
  761. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, rows.toArray("fitemno"));
  762. /**
  763. * 商品营销类别
  764. */
  765. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  766. saleclsnumsqlFactory.addParameter("siteid", siteid);
  767. saleclsnumsqlFactory.addParameter_in("fitemno", rows.toArray("fitemno"));
  768. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  769. HashMap<String, PaoRemote> itemmap = null;
  770. if (withprice) {
  771. /**
  772. * 获取商品相关信息
  773. */
  774. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + rows.getInWhere("fitemno") + " and siteid='" + siteid + "'");
  775. itemmap = getPaoMap(titemset, "fitemno");
  776. }
  777. /**
  778. * 遍历货品档案,设置商品信息
  779. */
  780. for (Row itemrow : rows) {
  781. String fitemno = itemrow.getString("fitemno");
  782. //图片
  783. itemrow.put("pics", picmap.get(fitemno));
  784. if (withprice) {
  785. titem titem = (titem) itemmap.get(fitemno);
  786. if (content.containsKey("fprojectnum") && !content.getString("fprojectnum").equals("")) {
  787. titem.fprojectnum = content.getString("fprojectnum");
  788. }
  789. double foldprice = titem.getCardPriceByAagentnum(fagentnum);
  790. double fprice = titem.getAgentSalePrice(foldprice, fagentnum);
  791. //牌价
  792. itemrow.put("foldprice", foldprice);
  793. //销售价
  794. itemrow.put("fprice", fprice);
  795. //营销分类
  796. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  797. }
  798. }
  799. return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
  800. }
  801. public String query_saler() throws Exception {
  802. /**
  803. * 创建数据库连接
  804. */
  805. DBConnect drpConnect = new DBConnect();
  806. /**
  807. *排序条件设置
  808. */
  809. String[] sortmsg = {"t1.fitemno", "t1.fitemname", "t1.fspec"};
  810. String sort = sortmsg[0];
  811. if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
  812. sort = content.getString("sort");
  813. }
  814. /**
  815. * 过滤条件设置
  816. */
  817. String where = " 1=1 ";
  818. if (content.containsKey("where")) {
  819. JSONObject whereObject = content.getJSONObject("where");
  820. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  821. where = where + " and(t1.fitemno like'%" + whereObject.getString("condition") + "%' or t1.fspec like '%" + whereObject.getString("condition") + "%' or t1.fitemname like'%" + whereObject.getString("condition") + "%' or t1.fmodel like'%" + whereObject.getString("condition") + "%')";
  822. }
  823. if (whereObject.containsKey("fspec") && !"".equals(whereObject.getString("fspec"))) {
  824. where = where + " and t1.fspec ='" + whereObject.getString("fspec") + "'";
  825. }
  826. if (whereObject.containsKey("fitemno") && !"".equals(whereObject.getString("fitemno"))) {
  827. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  828. }
  829. if (whereObject.containsKey("fsaleclsnum") && !"".equals(whereObject.getString("fsaleclsnum"))) {
  830. SQLFactory flongsaleslsFactory = new SQLFactory(this, "营销类别全路径查询");
  831. flongsaleslsFactory.addParameter("fsaleclsnum", whereObject.getString("fsaleclsnum"));
  832. flongsaleslsFactory.addParameter("siteid", siteid);
  833. Rows flongsaleslsRows = drpConnect.runSqlQuery(flongsaleslsFactory.getSQL());
  834. if (flongsaleslsRows.isEmpty()) {
  835. where = where + " and 1=2";
  836. } else {
  837. //where = where + " and t1.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%'";
  838. where = where + " and exists(select *from titem_saleclsnum where titem_saleclsnum.siteid=t1.siteid and titem_saleclsnum.fitemno=t1.fitemno and titem_saleclsnum.flongsaleclsnum like'" + flongsaleslsRows.get(0).getString("flongsaleslsnum") + "%') ";
  839. }
  840. }
  841. if (whereObject.containsKey("fiscollection") && !"".equals(whereObject.getString("fiscollection"))) {
  842. where = where + " and isnull(t4.fiscollection,0) ='" + whereObject.getString("fiscollection") + "'";
  843. }
  844. if (whereObject.containsKey("fiscustomized") && !"".equals(whereObject.getString("fiscustomized"))) {
  845. where = where + " and t1.fiscustomized ='" + whereObject.getString("fiscustomized") + "'";
  846. }
  847. if (whereObject.containsKey("fiswuliao") && !"".equals(whereObject.getString("fiswuliao"))) {
  848. where = where + " and t1.fiswuliao ='" + whereObject.getString("fiswuliao") + "'";
  849. }
  850. if (whereObject.containsKey("fieldname") && !"".equals(whereObject.getString("fieldname"))) {
  851. where = where + " and t1.fieldname ='" + whereObject.getString("fieldname") + "'";
  852. }
  853. if (whereObject.containsKey("fbrand") && !"".equals(whereObject.getString("fbrand"))) {
  854. where = where + " and t1.fbrand ='" + whereObject.getString("fbrand") + "'";
  855. }
  856. if (whereObject.containsKey("fistool") && !"".equals(whereObject.getString("fistool"))) {
  857. where = where + " and t1.fistool ='" + whereObject.getString("fistool") + "'";
  858. }
  859. if (whereObject.containsKey("fvalue8") && whereObject.getBoolean("fvalue8")) {
  860. //如果是中线碟阀
  861. where = where + " and t1.fvalue8=1";
  862. }
  863. if (whereObject.containsKey("fvalue7") && !"".equals(whereObject.getString("fvalue7"))) {
  864. where = where + " and t1.fvalue7 ='" + whereObject.getString("fvalue7") + "'";
  865. }
  866. if (whereObject.containsKey("fvalue6") && !"".equals(whereObject.getString("fvalue6"))) {
  867. where = where + " and t1.fvalue6 ='" + whereObject.getString("fvalue6") + "'";
  868. }
  869. if (whereObject.containsKey("fvalue5") && !"".equals(whereObject.getString("fvalue5"))) {
  870. where = where + " and t1.fvalue5 ='" + whereObject.getString("fvalue5") + "'";
  871. }
  872. if (whereObject.containsKey("fvalue4") && !"".equals(whereObject.getString("fvalue4"))) {
  873. where = where + " and t1.fvalue4 ='" + whereObject.getString("fvalue4") + "'";
  874. }
  875. if (whereObject.containsKey("fvalue3") && !"".equals(whereObject.getString("fvalue3"))) {
  876. where = where + " and t1.fvalue3 ='" + whereObject.getString("fvalue3") + "'";
  877. }
  878. if (whereObject.containsKey("fvalue2") && !"".equals(whereObject.getString("fvalue2"))) {
  879. where = where + " and t1.fvalue2 ='" + whereObject.getString("fvalue2") + "'";
  880. }
  881. if (whereObject.containsKey("fvalue1") && !"".equals(whereObject.getString("fvalue1"))) {
  882. where = where + " and t1.fvalue1 ='" + whereObject.getString("fvalue1") + "'";
  883. }
  884. }
  885. /**
  886. * SQL货品档案查询参数设置并查询
  887. */
  888. SQLFactory factory = new SQLFactory(this, "货品档案列表查询_业务员", pageSize, pageNumber, sort);
  889. factory.addParameter("siteid", siteid);
  890. factory.addParameter_SQL("where", where);
  891. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  892. /**
  893. * 获取品号批查条件
  894. */
  895. String itemwhere = rows.getInWhere("fitemno");
  896. String[] itemarray = rows.toArray("fitemno");
  897. /**
  898. *商品图片查询参数设置,并将结果存放置map
  899. */
  900. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, itemarray);
  901. /**
  902. *商品产品样册查询参数设置,并将结果存放置map
  903. */
  904. RowsMap samplebookmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_SAMPLEBOOK, itemarray);
  905. /**
  906. *商品说明书查询参数设置,并将结果存放置map
  907. */
  908. RowsMap instructionsmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTRUCTIONS, itemarray);
  909. /**
  910. *商品安装教程查询参数设置,并将结果存放置map
  911. */
  912. RowsMap installationtutorialmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTALLATIONTUTORIAL, itemarray);
  913. /**
  914. * 商品营销类别
  915. */
  916. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  917. saleclsnumsqlFactory.addParameter("siteid", siteid);
  918. saleclsnumsqlFactory.addParameter_in("fitemno", itemarray);
  919. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  920. /**
  921. *更新即时库存
  922. */
  923. new icinvbalMsg().caculate(siteid, rows.toArray("fitemno"), false);
  924. /**
  925. * 获取商品相关信息
  926. */
  927. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + itemwhere + " and siteid='" + siteid + "'");
  928. HashMap<String, PaoRemote> itemmap = getPaoMap(titemset, "fitemno");
  929. /**
  930. * 遍历货品档案,设置商品信息
  931. */
  932. for (Row itemrow : rows) {
  933. String fitemno = itemrow.getString("fitemno");
  934. titem titem = (titem) itemmap.get(fitemno);
  935. double foldprice = titem.getCardPriceByGrade("1");
  936. String fsaorderstockstatus = titem.getString("fsaorderstockstatus");
  937. double ficqty = titem.getDouble("ficqty");
  938. //库存状态
  939. itemrow.put("fsaorderstockstatus", fsaorderstockstatus);
  940. itemrow.put("ficqty", ficqty);
  941. //牌价
  942. itemrow.put("foldprice", foldprice);
  943. //销售价
  944. itemrow.put("fprice", foldprice);
  945. //图片
  946. itemrow.put("pics", picmap.get(fitemno));
  947. //产品样册
  948. itemrow.put("samplebook", samplebookmap.get(fitemno));
  949. //产品说明书
  950. itemrow.put("instructions", instructionsmap.get(fitemno));
  951. //安装教程
  952. itemrow.put("installationtutorial", installationtutorialmap.get(fitemno));
  953. //营销分类
  954. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  955. }
  956. titemset.close();
  957. return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
  958. }
  959. public String queryone() throws P2Exception {
  960. /**
  961. * 创建数据库连接
  962. */
  963. DBConnect drpConnect = new DBConnect();
  964. /**
  965. * 过滤条件设置
  966. */
  967. String where = " 1=1 ";
  968. if (content.containsKey("where")) {
  969. JSONObject whereObject = content.getJSONObject("where");
  970. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  971. }
  972. /**
  973. * SQL货品档案查询参数设置并查询
  974. */
  975. SQLFactory factory = new SQLFactory(this, "货品档案列表查询");
  976. factory.addParameter("fagentnum", fagentnum);
  977. factory.addParameter("siteid", siteid);
  978. factory.addParameter_SQL("where", where);
  979. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  980. /**
  981. * 获取品号批查条件
  982. */
  983. String itemwhere = rows.getInWhere("fitemno");
  984. String[] itemarray = rows.toArray("fitemno");
  985. /**
  986. *商品图片查询参数设置,并将结果存放置map
  987. */
  988. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, itemarray);
  989. /**
  990. *商品产品样册查询参数设置,并将结果存放置map
  991. */
  992. RowsMap samplebookmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_SAMPLEBOOK, itemarray);
  993. /**
  994. *商品说明书查询参数设置,并将结果存放置map
  995. */
  996. RowsMap instructionsmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTRUCTIONS, itemarray);
  997. /**
  998. *商品安装教程查询参数设置,并将结果存放置map
  999. */
  1000. RowsMap installationtutorialmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTALLATIONTUTORIAL, itemarray);
  1001. /**
  1002. * 商品营销类别
  1003. */
  1004. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  1005. saleclsnumsqlFactory.addParameter("siteid", siteid);
  1006. saleclsnumsqlFactory.addParameter_in("fitemno", itemarray);
  1007. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  1008. /**
  1009. *更新即时库存
  1010. */
  1011. new icinvbalMsg().caculate(siteid, rows.toArray("fitemno"), false);
  1012. /**
  1013. * 获取商品相关信息
  1014. */
  1015. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + itemwhere + " and siteid='" + siteid + "'");
  1016. HashMap<String, PaoRemote> itemmap = getPaoMap(titemset, "fitemno");
  1017. /**
  1018. * 遍历货品档案,设置商品信息
  1019. */
  1020. for (Row itemrow : rows) {
  1021. String fitemno = itemrow.getString("fitemno");
  1022. titem titem = (titem) itemmap.get(fitemno);
  1023. String fsaorderstockstatus = titem.getString("fsaorderstockstatus");
  1024. double ficqty = titem.getDouble("ficqty");
  1025. double foldprice = 0;
  1026. double fprice = 0;
  1027. if ("业务员".equals(usertype) && ("".equals(fagentnum) || fagentnum == null)) {
  1028. PaoSetRemote titemsaleprice = titem.getPaoSet("titemsaleprice");
  1029. if (!titemsaleprice.isEmpty()) {
  1030. foldprice = titemsaleprice.getPao(0).getDouble("fprice");
  1031. }
  1032. fprice = foldprice;
  1033. } else {
  1034. foldprice = titem.getCardPriceByAagentnum(fagentnum);
  1035. fprice = titem.getAgentSalePrice(foldprice, fagentnum);
  1036. }
  1037. //库存状态
  1038. itemrow.put("fsaorderstockstatus", fsaorderstockstatus);
  1039. itemrow.put("ficqty", ficqty);
  1040. //牌价
  1041. itemrow.put("foldprice", foldprice);
  1042. //销售价
  1043. itemrow.put("fprice", fprice);
  1044. //图片
  1045. itemrow.put("pics", picmap.get(fitemno));
  1046. //产品样册
  1047. itemrow.put("samplebook", samplebookmap.get(fitemno));
  1048. //产品说明书
  1049. itemrow.put("instructions", instructionsmap.get(fitemno));
  1050. //安装教程
  1051. itemrow.put("installationtutorial", installationtutorialmap.get(fitemno));
  1052. //营销分类
  1053. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  1054. }
  1055. titemset.close();
  1056. return getReturnObject_suc(rows, true).toString();
  1057. }
  1058. public String queryone_saler() throws P2Exception {
  1059. /**
  1060. * 创建数据库连接
  1061. */
  1062. DBConnect drpConnect = new DBConnect();
  1063. /**
  1064. * 过滤条件设置
  1065. */
  1066. String where = " 1=1 ";
  1067. if (content.containsKey("where")) {
  1068. JSONObject whereObject = content.getJSONObject("where");
  1069. where = where + " and t1.fitemno ='" + whereObject.getString("fitemno") + "'";
  1070. }
  1071. /**
  1072. * SQL货品档案查询参数设置并查询
  1073. */
  1074. SQLFactory factory = new SQLFactory(this, "货品档案列表查询_业务员");
  1075. factory.addParameter("fagentnum", fagentnum);
  1076. factory.addParameter("siteid", siteid);
  1077. factory.addParameter_SQL("where", where);
  1078. Rows rows = drpConnect.runSqlQuery(factory.getSQL());
  1079. /**
  1080. * 获取品号批查条件
  1081. */
  1082. String itemwhere = rows.getInWhere("fitemno");
  1083. String[] itemarray = rows.toArray("fitemno");
  1084. /**
  1085. *商品图片查询参数设置,并将结果存放置map
  1086. */
  1087. RowsMap picmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_PIC, itemarray);
  1088. /**
  1089. *商品产品样册查询参数设置,并将结果存放置map
  1090. */
  1091. RowsMap samplebookmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_SAMPLEBOOK, itemarray);
  1092. /**
  1093. *商品说明书查询参数设置,并将结果存放置map
  1094. */
  1095. RowsMap instructionsmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTRUCTIONS, itemarray);
  1096. /**
  1097. *商品安装教程查询参数设置,并将结果存放置map
  1098. */
  1099. RowsMap installationtutorialmap = RowsPool.getRowsMap(siteid, RowsPool.GroupName.ITEM_INSTALLATIONTUTORIAL, itemarray);
  1100. /**
  1101. * 商品营销类别
  1102. */
  1103. SQLFactory saleclsnumsqlFactory = new SQLFactory(this, "货品营销类别查询");
  1104. saleclsnumsqlFactory.addParameter("siteid", siteid);
  1105. saleclsnumsqlFactory.addParameter_in("fitemno", itemarray);
  1106. RowsMap saleclsnumRowsMap = drpConnect.runSqlQuery(saleclsnumsqlFactory.getSQL()).toRowsMap("fitemno");
  1107. /**
  1108. *更新即时库存
  1109. */
  1110. new icinvbalMsg().caculate(siteid, rows.toArray("fitemno"), false);
  1111. /**
  1112. * 获取商品相关信息
  1113. */
  1114. PaoSetRemote titemset = getP2ServerPaoSet("titem", hrid, "fitemno in " + itemwhere + " and siteid='" + siteid + "'");
  1115. HashMap<String, PaoRemote> itemmap = getPaoMap(titemset, "fitemno");
  1116. /**
  1117. * 遍历货品档案,设置商品信息
  1118. */
  1119. for (Row itemrow : rows) {
  1120. String fitemno = itemrow.getString("fitemno");
  1121. titem titem = (titem) itemmap.get(fitemno);
  1122. String fsaorderstockstatus = titem.getString("fsaorderstockstatus");
  1123. double ficqty = titem.getDouble("ficqty");
  1124. double foldprice = 0;
  1125. double fprice = 0;
  1126. if ("业务员".equals(usertype) && ("".equals(fagentnum) || fagentnum == null)) {
  1127. PaoSetRemote titemsaleprice = titem.getPaoSet("titemsaleprice");
  1128. if (!titemsaleprice.isEmpty()) {
  1129. foldprice = titemsaleprice.getPao(0).getDouble("fprice");
  1130. }
  1131. fprice = foldprice;
  1132. } else {
  1133. foldprice = titem.getCardPriceByAagentnum(fagentnum);
  1134. fprice = titem.getAgentSalePrice(foldprice, fagentnum);
  1135. }
  1136. //库存状态
  1137. itemrow.put("fsaorderstockstatus", fsaorderstockstatus);
  1138. itemrow.put("ficqty", ficqty);
  1139. //牌价
  1140. itemrow.put("foldprice", foldprice);
  1141. //销售价
  1142. itemrow.put("fprice", fprice);
  1143. //图片
  1144. itemrow.put("pics", picmap.get(fitemno));
  1145. //产品样册
  1146. itemrow.put("samplebook", samplebookmap.get(fitemno));
  1147. //产品说明书
  1148. itemrow.put("instructions", instructionsmap.get(fitemno));
  1149. //安装教程
  1150. itemrow.put("installationtutorial", installationtutorialmap.get(fitemno));
  1151. //营销分类
  1152. itemrow.put("saleclsnum", saleclsnumRowsMap.get(fitemno));
  1153. }
  1154. titemset.close();
  1155. return getReturnObject_suc(rows, true).toString();
  1156. }
  1157. /**
  1158. * 查询商品图片
  1159. * @return
  1160. */
  1161. public String query_itempic() {
  1162. Rows picrows = RowsPool.getRows(siteid, RowsPool.GroupName.ITEM_PIC, content.getString("fitemno"));
  1163. return getReturnObject_suc(picrows, true).toString();
  1164. }
  1165. /**
  1166. * 商品收藏
  1167. * @return
  1168. */
  1169. public String collection() throws Exception {
  1170. // 商品编号
  1171. String fitemno = content.getString("fitemno");
  1172. //是否收藏
  1173. int fiscollection = content.getInt("fiscollection");
  1174. PaoSetRemote tfavorites = getP2ServerPaoSet("tfavorites", hrid, "fagentnum='" + fagentnum + "' and fitemno='" + fitemno + "'");
  1175. PaoRemote pao = null;
  1176. if (tfavorites.isEmpty()) {
  1177. pao = tfavorites.addAtEnd();
  1178. pao.setValue("fitemno", fitemno, 11L);
  1179. pao.setValue("fagentnum", fagentnum, 11L);
  1180. } else {
  1181. pao = tfavorites.getPao(0);
  1182. }
  1183. pao.setValue("fiscollection", fiscollection == 1, 11L);
  1184. tfavorites.save();
  1185. tfavorites.close();
  1186. return getReturnObject_suc().toString();
  1187. }
  1188. /**
  1189. * 商品定制信息查询
  1190. * @return
  1191. */
  1192. public String query_Customized() {
  1193. /**
  1194. * 创建数据库连接
  1195. */
  1196. DBConnect connect = new DBConnect();
  1197. /**
  1198. * SQL定制信息列表查询参数设置并查询
  1199. */
  1200. SQLFactory factory = new SQLFactory(this, "定制信息列表查询");
  1201. factory.addParameter("fitemno", content.getString("fitemno"));
  1202. factory.addParameter("siteid", siteid);
  1203. Rows rows = connect.runSqlQuery(factory.getSQL());
  1204. for (Row row : rows) {
  1205. SQLFactory detailfac = new SQLFactory(this, "定制信息列表选项查询");
  1206. detailfac.addParameter("titem_customizedid", row.getString("titem_customizedid"));
  1207. Rows optionsRows = connect.runSqlQuery(detailfac.getSQL());
  1208. row.put("options", optionsRows.toJsonArray("fvalue"));
  1209. }
  1210. return getReturnObject_suc(rows, true).toString();
  1211. }
  1212. /**
  1213. * 商品品牌查询
  1214. * @return
  1215. */
  1216. public String query_BrandList() {
  1217. /**
  1218. * 创建数据库连接
  1219. */
  1220. DBConnect connect = new DBConnect();
  1221. /**
  1222. * SQL定制信息列表查询参数设置并查询
  1223. */
  1224. SQLFactory factory = new SQLFactory(this, "品牌列表查询");
  1225. factory.addParameter("siteid", siteid);
  1226. Rows rows = connect.runSqlQuery(factory.getSQL());
  1227. return getReturnObject_suc(rows, true).toString();
  1228. }
  1229. public String query_itemvalueclass() {
  1230. SQLFactory sqlFactory = new SQLFactory(this, "商品档案选项查询");
  1231. sqlFactory.addParameter("siteid", siteid);
  1232. DBConnect dbConnect = new DBConnect();
  1233. RowsMap rowsMap = dbConnect.runSqlQuery(sqlFactory.getSQL()).toRowsMap("field");
  1234. JSONObject object = new JSONObject();
  1235. for (String field : rowsMap.keySet()) {
  1236. object.put(field, rowsMap.get(field).toJsonArray("value"));
  1237. }
  1238. return getReturnObject_suc(object, true).toString();
  1239. }
  1240. }