itemclass.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. package restcontroller.webmanage.sale.itemclass;
  2. import beans.datacontrllog.DataContrlLog;
  3. import beans.enterprise.Enterprise;
  4. import beans.itemclass.ItemClass;
  5. import com.alibaba.fastjson2.JSONArray;
  6. import com.alibaba.fastjson2.JSONObject;
  7. import common.Controller;
  8. import common.YosException;
  9. import common.annotation.API;
  10. import common.annotation.CACHEING;
  11. import common.annotation.CACHEING_CLEAN;
  12. import common.annotation.cm;
  13. import common.data.Row;
  14. import common.data.Rows;
  15. import common.data.RowsMap;
  16. import common.data.SQLFactory;
  17. import restcontroller.R;
  18. import java.util.ArrayList;
  19. import java.util.Collections;
  20. @API(title = "营销类别")
  21. public class itemclass extends Controller {
  22. public itemclass(JSONObject arg0) throws YosException {
  23. super(arg0);
  24. // TODO Auto-generated constructor stub
  25. }
  26. /**
  27. * 新增修改营销类别
  28. *
  29. * @return
  30. */
  31. @API(title = "营销类别新增修改", apiversion = R.ID20220922110303.v1.class, intervaltime = 200)
  32. @CACHEING_CLEAN(cms = {@cm(clazz = itemclass.class, method = {"queryItemclass", "queryItemclassLaststage"})})
  33. public String insertormodify_itemclass() throws YosException {
  34. long itemclassid = content.getLong("itemclassid");
  35. long sa_brandid = content.getLong("sa_brandid");
  36. long parentid = content.getLong("parentid");
  37. // String itemclassfullname = content.getString("itemclassfullname");
  38. String itemclassnum = content.getString("itemclassnum");
  39. String itemclassname = content.getString("itemclassname");
  40. String classtype = content.getString("classtype");
  41. String num = content.getStringValue("num");
  42. boolean ishide = content.getBooleanValue("ishide");
  43. boolean istool = content.getBooleanValue("istool");
  44. ArrayList<String> sqllist = new ArrayList<>();
  45. if (itemclassid <= 0 || dbConnect
  46. .runSqlQuery("select itemclassid from plm_itemclass where itemclassid=" + itemclassid).isEmpty()) {
  47. Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM plm_itemclass WHERE sa_brandid='" + sa_brandid
  48. + "' and itemclassnum = '" + itemclassnum + "' and siteid='" + siteid + "'");
  49. Rows rowsname = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM plm_itemclass WHERE sa_brandid='"
  50. + sa_brandid + "' and itemclassname = '" + itemclassname + "' and siteid='" + siteid + "'");
  51. if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
  52. return getErrReturnObject().setErrMsg("营销类别已存在").toString();
  53. }
  54. // if (!rowsname.isEmpty() && rowsname.get(0).getLong("count") > 0) {
  55. // return getErrReturnObject().setErrMsg("营销类别已存在").toString();
  56. // }
  57. SQLFactory sqlAddFactory = new SQLFactory(this, "营销类别新增");
  58. itemclassid = createTableID("plm_itemclass");
  59. sqlAddFactory.addParameter("itemclassid", itemclassid);
  60. sqlAddFactory.addParameter("siteid", siteid);
  61. sqlAddFactory.addParameter("itemclassnum", itemclassnum);
  62. sqlAddFactory.addParameter("itemclassname", itemclassname);
  63. sqlAddFactory.addParameter("username", username);
  64. sqlAddFactory.addParameter("userid", userid);
  65. if (parentid == 0) {
  66. sqlAddFactory.addParameter("istool", istool);
  67. } else {
  68. Rows toolRows = dbConnect.runSqlQuery("select itemclassid,istool from plm_itemclass where itemclassid="
  69. + parentid + " and siteid='" + siteid + "'");
  70. if (!toolRows.isEmpty()) {
  71. sqlAddFactory.addParameter("istool", toolRows.get(0).getLong("istool"));
  72. } else {
  73. return getErrReturnObject().setErrMsg("上级类别不存在").toString();
  74. }
  75. }
  76. sqlAddFactory.addParameter("parentid", parentid);
  77. sqlAddFactory.addParameter("itemclassfullname",
  78. getUppeItemclassfullname(itemclassname, parentid, itemclassid));
  79. sqlAddFactory.addParameter("itemclassfullnum",
  80. getUppeItemclassfullnum(itemclassnum, parentid, itemclassid));
  81. sqlAddFactory.addParameter("classtype", classtype);
  82. sqlAddFactory.addParameter("num", num);
  83. sqlAddFactory.addParameter("ishide", ishide);
  84. sqlAddFactory.addParameter("sa_brandid", sa_brandid);
  85. sqlAddFactory.addParameter("isdeep", 1);
  86. sqlAddFactory.addParameter("level", 1);
  87. if (parentid > 0) {
  88. sqllist = getItemclasslevel(1, parentid, itemclassid, sqllist);
  89. sqllist.add("update plm_itemclass set isdeep=0 where itemclassid=" + parentid);
  90. }
  91. sqllist.add(sqlAddFactory.getSQL());
  92. sqllist.add(DataContrlLog.createLog(this, "plm_itemclass", classtype.equals("营销")?1:2, "新增", itemclassnum+classtype+"类别新增成功")
  93. .getSQL());
  94. } else {
  95. Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM plm_itemclass WHERE sa_brandid='" + sa_brandid
  96. + "' and itemclassid!=" + content.getLong("itemclassid") + " and itemclassnum = '" + itemclassnum
  97. + "' and siteid='" + siteid + "'");
  98. Rows rowsname = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM plm_itemclass WHERE sa_brandid='"
  99. + sa_brandid + "' and itemclassid!=" + content.getLong("itemclassid") + " and itemclassname = '"
  100. + itemclassname + "' and siteid='" + siteid + "'");
  101. Rows itemclassnameOldRows = dbConnect.runSqlQuery(
  102. "SELECT itemclassname,itemclassfullname,itemclassfullnum FROM plm_itemclass WHERE sa_brandid='"
  103. + sa_brandid + "' and itemclassid=" + content.getLong("itemclassid") + " and siteid='"
  104. + siteid + "'");
  105. if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
  106. return getErrReturnObject().setErrMsg("营销类别已存在").toString();
  107. }
  108. // if (!rowsname.isEmpty() && rowsname.get(0).getLong("count") > 0) {
  109. // return getErrReturnObject().setErrMsg("营销类别已存在").toString();
  110. // }
  111. String itemclassnameOld = "";
  112. if (!itemclassnameOldRows.isEmpty()) {
  113. itemclassnameOld = itemclassnameOldRows.get(0).getString("itemclassname");
  114. }
  115. SQLFactory sqlUpdateFactory = new SQLFactory(this, "营销类别更新");
  116. sqlUpdateFactory.addParameter("itemclassid", itemclassid);
  117. sqlUpdateFactory.addParameter("siteid", siteid);
  118. sqlUpdateFactory.addParameter("itemclassname", itemclassname);
  119. sqlUpdateFactory.addParameter("username", username);
  120. sqlUpdateFactory.addParameter("userid", userid);
  121. // sqlUpdateFactory.addParameter("itemclassfullname",
  122. // getUppeItemclassfullname(itemclassname, parentid, itemclassid));
  123. // sqlUpdateFactory.addParameter("itemclassfullnum",
  124. // getUppeItemclassfullnum(itemclassnum, parentid, itemclassid));
  125. if (!itemclassnameOldRows.get(0).getString("itemclassfullname").contains("/")) {
  126. sqlUpdateFactory.addParameter("itemclassfullname", itemclassname);
  127. } else {
  128. sqlUpdateFactory.addParameter("itemclassfullname",
  129. itemclassnameOldRows.get(0).getString("itemclassfullname").substring(0,
  130. itemclassnameOldRows.get(0).getString("itemclassfullname").lastIndexOf("/")) + "/"
  131. + itemclassname);
  132. }
  133. sqlUpdateFactory.addParameter("itemclassfullnum",
  134. itemclassnameOldRows.get(0).getString("itemclassfullnum"));
  135. sqlUpdateFactory.addParameter("classtype", classtype);
  136. sqlUpdateFactory.addParameter("num", num);
  137. sqlUpdateFactory.addParameter("ishide", ishide);
  138. if (parentid == 0) {
  139. sqlUpdateFactory.addParameter("istool", istool);
  140. ArrayList<Long> list = new ArrayList<Long>();
  141. list.add(itemclassid);
  142. ArrayList<Long> Sublist = ItemClass.getSubItemClassIds(this, list);
  143. Sublist.add((long) 0);
  144. String sqlString = "update plm_itemclass set istool=" + istool + " where itemclassid in" + Sublist;
  145. sqlString = sqlString.replace("[", "(").replace("]", ")");
  146. sqllist.add(sqlString);
  147. } else {
  148. Rows toolRows = dbConnect.runSqlQuery("select itemclassid,istool from plm_itemclass where itemclassid="
  149. + parentid + " and siteid='" + siteid + "'");
  150. if (!toolRows.isEmpty()) {
  151. sqlUpdateFactory.addParameter("istool", toolRows.get(0).getLong("istool"));
  152. } else {
  153. return getErrReturnObject().setErrMsg("上级类别不存在").toString();
  154. }
  155. }
  156. if (!itemclassnameOld.equals("")) {
  157. sqllist.addAll(getLowerItemclassUpdateSql(itemclassid, itemclassnameOld, itemclassname));
  158. }
  159. sqllist.add(sqlUpdateFactory.getSQL());
  160. sqllist.add(DataContrlLog.createLog(this, "plm_itemclass", classtype.equals("营销")?1:2, "更新", itemclassnum+classtype+"类别更新成功")
  161. .getSQL());
  162. }
  163. dbConnect.runSqlUpdate(sqllist);
  164. return getSucReturnObject().toString();
  165. }
  166. @API(title = "营销类别新增修改", apiversion = R.ID20240902145303.v1.class, intervaltime = 200)
  167. @CACHEING_CLEAN(cms = {@cm(clazz = itemclass.class, method = {"queryItemclass", "queryItemclassLaststage"})})
  168. public String modify_itemclassNum() throws YosException {
  169. JSONArray itemclassinfos = content.getJSONArray("itemclassinfos");
  170. ArrayList<String> sqlList = new ArrayList<>();
  171. for (Object obj : itemclassinfos) {
  172. JSONObject itemclassinfo = (JSONObject) obj;
  173. sqlList.add("update plm_itemclass set num='" + itemclassinfo.getString("num") + "' where itemclassid=" + itemclassinfo.getLong("itemclassid"));
  174. }
  175. dbConnect.runSqlUpdate(sqlList);
  176. return getSucReturnObject().toString();
  177. }
  178. /**
  179. * 查询营销类别
  180. *
  181. * @return
  182. */
  183. @API(title = "查询", apiversion = R.ID20220922110403.v1.class)
  184. @CACHEING(life = 10)
  185. public String queryItemclass() throws YosException {
  186. long sa_brandid = content.getLongValue("sa_brandid");
  187. if (content.containsKey("sys_enterpriseid")) {
  188. sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  189. }
  190. String where = " 1=1 ";
  191. String where2 = " 1=1 ";
  192. if (content_where.containsKey("istool") && !"".equals(content_where.getString("istool"))) {
  193. where = where + " and (ifnull(t1.istool,0) ='" + content_where.getString("istool") + "') ";
  194. where2 = where2 + " and (ifnull(t2.istool,0) ='" + content_where.getString("istool") + "') ";
  195. }
  196. if (content_where.containsKey("ishide") && !"".equals(content_where.getString("ishide"))) {
  197. where = where + " and (ifnull(t1.ishide,0) ='" + content_where.getString("ishide") + "') ";
  198. where2 = where2 + " and (ifnull(t2.ishide,0) ='" + content_where.getString("ishide") + "') ";
  199. }
  200. if (sys_enterpriseid > 0 && content.getStringValue("classtype").equalsIgnoreCase("营销")) {
  201. Row enterpriseRow = Enterprise.getEnterprise(this, sys_enterpriseid);
  202. if (!enterpriseRow.isEmpty()) {
  203. if (enterpriseRow.getBoolean("saleclassauth")) {
  204. where = where + " and t1.itemclassid in ( SELECT itemclassid from sys_enterprise_saleclass WHERE sys_enterpriseid = "
  205. + sys_enterpriseid + " and siteid='" + siteid + "')";
  206. }
  207. }
  208. }
  209. Rows rows = Enterprise.getBrands(this, sys_enterpriseid);
  210. if (sa_brandid > 0) {
  211. rows = rows.filter("sa_brandid", sa_brandid);
  212. }
  213. for (Row row : rows) {
  214. //查询所有分类
  215. SQLFactory sqlFactory = new SQLFactory(this, "查询所有分类");
  216. sqlFactory.addParameter("siteid", siteid);
  217. sqlFactory.addParameter("sa_brandid", row.getString("sa_brandid"));
  218. sqlFactory.addParameter("classtype", content.getStringValue("classtype"));
  219. sqlFactory.addParameter_SQL("where", where);
  220. sqlFactory.addParameter_SQL("where2", where2);
  221. Rows allrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  222. if (content.getBooleanValue("isnottree")) {
  223. row.put("ttemclass", allrows);
  224. } else {
  225. /*
  226. * 获取所有一级分类
  227. */
  228. RowsMap allrowsMap = allrows.toRowsMap("parentid");
  229. Rows toprows = allrows.toRowsMap("parentid").get("0");
  230. Collections.sort(toprows, new SortByNum());
  231. /*
  232. * 递归查询
  233. */
  234. for (Row row1 : toprows) {
  235. Rows rows1 = getSubItemclass(row1, allrowsMap);
  236. row1.put("subdep", rows1);
  237. }
  238. row.put("ttemclass", toprows);
  239. }
  240. }
  241. return getSucReturnObject().setData(rows).toString();
  242. }
  243. /**
  244. * 递归查询下级产品类别
  245. *
  246. * @param root
  247. * @param allrowsMap
  248. * @return
  249. */
  250. private Rows getSubItemclass(Row root, RowsMap allrowsMap) {
  251. Rows childrenRows = allrowsMap.get(root.getString("itemclassid"));
  252. Collections.sort(childrenRows, new SortByNum());
  253. for (Row row : childrenRows) {
  254. row.put("subdep", getSubItemclass(row, allrowsMap));
  255. }
  256. return childrenRows;
  257. }
  258. /**
  259. * 查询单据可添加营销类别
  260. *
  261. * @return
  262. */
  263. @API(title = "查询单据可添加营销类别", apiversion = R.ID20230818135003.v1.class)
  264. @CACHEING
  265. public String queryItemclassAccordingtoId() throws YosException {
  266. long sa_brandid = content.getLongValue("sa_brandid");
  267. // long istool = content.getLongValue("istool");
  268. String where = " 1=1 ";
  269. if (content.containsKey("where")) {
  270. JSONObject whereObject = content.getJSONObject("where");
  271. if (whereObject.containsKey("istool") && !"".equals(whereObject.getString("istool"))) {
  272. where = where + " and (ifnull(t1.istool,0) ='" + whereObject.getString("istool") + "') ";
  273. }
  274. }
  275. if (content.containsKey("sys_enterpriseid")) {
  276. if (content.getLong("sys_enterpriseid") > 0) {
  277. where = where + " and t1.itemclassid not in (SELECT ifnull(itemclassid,0) from sys_enterprise_saleclass WHERE sys_enterpriseid = " +
  278. content.getLong("sys_enterpriseid") + " and siteid='" + siteid + "' )";
  279. }
  280. }
  281. if (content.containsKey("sa_rebateschemeid")) {
  282. if (content.getLong("sa_rebateschemeid") > 0) {
  283. where = where + " and not exists (SELECT 1 from sa_rebatecategory WHERE sa_rebateschemeid = " +
  284. content.getLong("sa_rebateschemeid") + " and itemclassid=t1.itemclassid and siteid='" + siteid + "' )";
  285. }
  286. }
  287. /*
  288. * SQL通告板块查询参数设置并查询
  289. */
  290. Rows rows = Enterprise.getBrands(this, sys_enterpriseid);
  291. if (!rows.isEmpty()) {
  292. for (Row row : rows) {
  293. /*
  294. * 查询所有分类
  295. */
  296. SQLFactory sqlFactory = new SQLFactory(this, "查询所有分类");
  297. sqlFactory.addParameter("siteid", siteid);
  298. sqlFactory.addParameter("sa_brandid", row.getString("sa_brandid"));
  299. sqlFactory.addParameter("classtype", content.getStringValue("classtype"));
  300. sqlFactory.addParameter_SQL("where", where);
  301. sqlFactory.addParameter_SQL("where2", " 1=1 ");
  302. String sql = sqlFactory.getSQL();
  303. Rows allrows = dbConnect.runSqlQuery(sql);
  304. /*
  305. * 获取所有一级分类
  306. */
  307. RowsMap allrowsMap = allrows.toRowsMap("parentid");
  308. Rows toprows = allrows.toRowsMap("parentid").get("0");
  309. Collections.sort(toprows, new SortByNum());
  310. /*
  311. * 递归查询
  312. */
  313. for (Row row1 : toprows) {
  314. Rows rows1 = getSubItemclass(row1, allrowsMap);
  315. //Collections.sort(rows1, new SortByNum());
  316. row1.put("subdep", rows1);
  317. }
  318. row.put("ttemclass", toprows);
  319. }
  320. }
  321. if (sa_brandid > 0) {
  322. Rows rows2 = new Rows();
  323. if (!rows.isEmpty()) {
  324. for (Row row : rows) {
  325. if (row.getLong("sa_brandid") == sa_brandid) {
  326. rows2.add(row);
  327. }
  328. }
  329. }
  330. if (rows2.isNotEmpty()) {
  331. if (((Rows) rows2.get(0).get("ttemclass")).isNotEmpty()) {
  332. Collections.sort((Rows) rows2.get(0).get("ttemclass"), new SortByNum());
  333. }
  334. }
  335. return getSucReturnObject().setData(rows2).toString();
  336. }
  337. return getSucReturnObject().setData(rows).toString();
  338. }
  339. /**
  340. * 查询末级营销类别
  341. *
  342. * @return
  343. */
  344. @API(title = "查询", apiversion = R.ID20220927102603.v1.class)
  345. @CACHEING
  346. public String queryItemclassLaststage() throws YosException {
  347. // long sa_brandid = content.getLong("sa_brandid");
  348. /*
  349. * 过滤条件设置
  350. */
  351. String where = " 1=1 ";
  352. if (content.containsKey("where")) {
  353. JSONObject whereObject = content.getJSONObject("where");
  354. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  355. where = where + " and (t1.itemclassname like'%" + whereObject.getString("condition") + "%') ";
  356. }
  357. if (whereObject.containsKey("istool") && !"".equals(whereObject.getString("istool"))) {
  358. where = where + " and t1.istool=" + whereObject.getLongValue("istool");
  359. }
  360. }
  361. SQLFactory factory = new SQLFactory(this, "营销类别末级列表查询");
  362. factory.addParameter("siteid", siteid);
  363. factory.addParameter_SQL("where", where);
  364. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  365. return getSucReturnObject().setData(rows).toString();
  366. }
  367. @API(title = "删除", apiversion = R.ID20220922110503.v1.class)
  368. @CACHEING_CLEAN(cms = {@cm(clazz = itemclass.class, method = {"queryItemclass"})})
  369. public String delete() throws YosException {
  370. Long itemclassid = content.getLong("itemclassid");
  371. Rows rowscount = dbConnect.runSqlQuery(
  372. "select isdeep,ifnull(parentid,0) parentid,itemclassnum from plm_itemclass where itemclassid=" + itemclassid);
  373. if (rowscount.isEmpty()) {
  374. return getErrReturnObject().setErrMsg("此营销类别不存在,无法删除").toString();
  375. } else {
  376. if (!rowscount.get(0).getBoolean("isdeep")) {
  377. return getErrReturnObject().setErrMsg("此营销类别非末级,无法删除").toString();
  378. }
  379. }
  380. Rows row = dbConnect.runSqlQuery("select itemid from sa_itemsaleclass where itemclassid=" + itemclassid);
  381. if (!row.isEmpty()) {
  382. return getErrReturnObject().setErrMsg("此营销类别下存在商品,无法删除").toString();
  383. }
  384. ArrayList<String> sqllist = new ArrayList<>();
  385. sqllist.add("update plm_itemclass set isdeep=1 where itemclassid=" + rowscount.get(0).getLong("parentid"));
  386. String deletesql = "DELETE FROM plm_itemclass WHERE itemclassid = '" + itemclassid + "'";
  387. sqllist.add(deletesql);
  388. sqllist.add(DataContrlLog.createLog(this, "plm_itemclass", rowscount.get(0).getString("classtype").equals("营销")?1:2, "删除", rowscount.get(0).getString("itemclassnum")+rowscount.get(0).getString("classtype")+"类别删除成功")
  389. .getSQL());
  390. dbConnect.runSqlUpdate(sqllist);
  391. return getSucReturnObject().toString();
  392. }
  393. private ArrayList<String> getItemclasslevel(int level, long parentid, long itemclassid, ArrayList<String> sqllist)
  394. throws YosException {
  395. if (parentid > 0) {
  396. Rows rows = dbConnect.runSqlQuery(
  397. "select ifnull(parentid,0) as parentid from plm_itemclass where classtype='营销' and itemclassid= '"
  398. + parentid + "'");
  399. if (!rows.isEmpty()) {
  400. level++;
  401. sqllist.add("update plm_itemclass set level='" + level + "' where itemclassid= '" + parentid + "'");
  402. getItemclasslevel(level, rows.get(0).getLong("parentid"), rows.get(0).getLong("itemclassid"), sqllist);
  403. }
  404. }
  405. return sqllist;
  406. }
  407. private String getUppeItemclassfullnum(String fullname, long parentid, long itemclassid) throws YosException {
  408. String fullnum = "";
  409. if (parentid > 0) {
  410. Rows rows = dbConnect.runSqlQuery(
  411. "select ifnull(parentid,0) as parentid,itemclassfullnum from plm_itemclass where classtype='营销' and itemclassid= '"
  412. + parentid + "'");
  413. if (!rows.isEmpty()) {
  414. fullnum = rows.get(0).getString("itemclassfullnum") + "/" + fullname;
  415. }
  416. } else {
  417. fullnum = fullname;
  418. }
  419. return fullnum;
  420. }
  421. private String getUppeItemclassfullname(String fullname, long parentid, long itemclassid) throws YosException {
  422. String fullnum = "";
  423. if (parentid > 0) {
  424. Rows rows = dbConnect.runSqlQuery(
  425. "select ifnull(parentid,0) as parentid,itemclassfullname from plm_itemclass where classtype='营销' and itemclassid= '"
  426. + parentid + "'");
  427. if (!rows.isEmpty()) {
  428. fullnum = rows.get(0).getString("itemclassfullname") + "/" + fullname;
  429. }
  430. } else {
  431. fullnum = fullname;
  432. }
  433. return fullnum;
  434. }
  435. /**
  436. * 根据指定的营销类别id获取下级营销类别id及营销路径名
  437. *
  438. * @param controller
  439. * @param itemclassid
  440. * @throws YosException
  441. */
  442. public static Rows getSubItemclass(Controller controller, long itemclassid) throws YosException {
  443. SQLFactory sqlFactory = new SQLFactory(controller, "下级营销类别获取");
  444. sqlFactory.addParameter("siteid", controller.siteid);
  445. sqlFactory.addParameter("itemclassid", itemclassid);
  446. Rows rows = controller.dbConnect.runSqlQuery(sqlFactory.getSQL());
  447. return rows;
  448. }
  449. private ArrayList<String> getLowerItemclassUpdateSql(long itemclassid, String itemclassnameOld,
  450. String itemclassnameNew) throws YosException {
  451. ArrayList<String> sqlList = new ArrayList<String>();
  452. Rows rows = getSubItemclass(this, itemclassid);
  453. if (!rows.isEmpty()) {
  454. for (Row row : rows) {
  455. if (row.getString("itemclassfullname").contains(itemclassnameOld)) {
  456. String itemclassfullname = row.getString("itemclassfullname").replace(itemclassnameOld,
  457. itemclassnameNew);
  458. String sql = "update plm_itemclass set itemclassfullname='" + itemclassfullname
  459. + "' where itemclassid=" + row.getLong("itemclassid");
  460. sqlList.add(sql);
  461. }
  462. }
  463. }
  464. return sqlList;
  465. }
  466. }