dispatchItems.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. package restcontroller.webmanage.sale.dispatch;
  2. import beans.data.BatchDeleteErr;
  3. import beans.parameter.Parameter;
  4. import com.alibaba.fastjson.JSONArray;
  5. import com.alibaba.fastjson.JSONObject;
  6. import common.Controller;
  7. import common.YosException;
  8. import common.annotation.API;
  9. import common.annotation.CACHEING;
  10. import common.annotation.CACHEING_CLEAN;
  11. import common.data.*;
  12. import org.apache.commons.lang.StringUtils;
  13. import org.apache.poi.ss.usermodel.CellStyle;
  14. import org.apache.poi.ss.usermodel.DataFormat;
  15. import org.apache.poi.xssf.usermodel.XSSFCellStyle;
  16. import org.apache.poi.xssf.usermodel.XSSFSheet;
  17. import org.apache.poi.xssf.usermodel.XSSFWorkbook;
  18. import restcontroller.R;
  19. import restcontroller.webmanage.sale.order.Order;
  20. import restcontroller.webmanage.sale.order.OrderItems;
  21. import utility.ERPDocking;
  22. import java.io.IOException;
  23. import java.math.BigDecimal;
  24. import java.util.ArrayList;
  25. import java.util.HashMap;
  26. public class dispatchItems extends Controller {
  27. public dispatchItems(JSONObject arg0) throws YosException {
  28. super(arg0);
  29. // TODO Auto-generated constructor stub
  30. }
  31. @API(title = "审核订单列表查询", apiversion = R.ID20221114165903.v1.class)
  32. @CACHEING
  33. public String queryCheckOrderList() throws YosException {
  34. /*
  35. * 过滤条件设置
  36. */
  37. StringBuffer where = new StringBuffer(" 1=1 ");
  38. if (content.containsKey("where")) {
  39. JSONObject whereObject = content.getJSONObject("where");
  40. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  41. where.append(" and(");
  42. where.append("t1.sonum like'%").append(whereObject.getString("condition")).append("%' ");
  43. where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
  44. where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  45. where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  46. where.append(")");
  47. }
  48. if (whereObject.containsKey("sonum") && !"".equals(whereObject.getString("sonum"))) {
  49. where.append(" and t1.sonum ='").append(whereObject.getString("sonum")).append("' ");
  50. }
  51. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  52. where.append(" and t1.checkdate >='").append(whereObject.getString("begindate")).append("' ");
  53. }
  54. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  55. where.append(" and t1.checkdate <='").append(whereObject.getString("enddate")).append("' ");
  56. }
  57. }
  58. // String hrid = content.getString("hrid");
  59. SQLFactory sqlFactory = new SQLFactory(this, "审核订单列表查询", pageSize, pageNumber, pageSorting);
  60. sqlFactory.addParameter_SQL("where", where);
  61. sqlFactory.addParameter("sys_enterpriseid", content.getLong("sys_enterpriseid"));
  62. sqlFactory.addParameter("siteid", siteid);
  63. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL(false));
  64. return getSucReturnObject().setData(rows).toString();
  65. }
  66. @API(title = "发货商品列表查询", apiversion = R.ID20221114170003.v1.class)
  67. @CACHEING
  68. public String queryOrderItemgList() throws YosException {
  69. /*
  70. * 过滤条件设置
  71. */
  72. StringBuffer where = new StringBuffer(" 1=1 ");
  73. if (content.containsKey("where")) {
  74. JSONObject whereObject = content.getJSONObject("where");
  75. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  76. where.append(" and(");
  77. where.append("t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  78. where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  79. where.append("or t1.unit like'%").append(whereObject.getString("condition")).append("%' ");
  80. where.append("or t3.sonum like'%").append(whereObject.getString("condition")).append("%' ");
  81. where.append(")");
  82. }
  83. if (whereObject.containsKey("sa_orderid") && !"".equals(whereObject.getString("sa_orderid"))) {
  84. where.append(" and t1.sa_orderid ='").append(whereObject.getString("sa_orderid")).append("' ");
  85. }
  86. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  87. where.append(" and t3.checkdate >='").append(whereObject.getString("begindate")).append("' ");
  88. }
  89. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  90. where.append(" and t3.checkdate <='").append(whereObject.getString("enddate")).append("' ");
  91. }
  92. }
  93. SQLFactory sqlFactory = new SQLFactory(this, "发货商品列表查询", pageSize, pageNumber, pageSorting);
  94. sqlFactory.addParameter_SQL("where", where);
  95. sqlFactory.addParameter("sys_enterpriseid", content.getLongValue("sys_enterpriseid"));
  96. sqlFactory.addParameter("sa_dispatchid", content.getLongValue("sa_dispatchid"));
  97. sqlFactory.addParameter("siteid", siteid);
  98. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL(false));
  99. return getSucReturnObject().setData(rows).toString();
  100. }
  101. @API(title = "erp批次库存查询", apiversion = R.ID20230427101303.v1.class)
  102. @CACHEING
  103. public String queryErpIcinvbalBatchList() throws YosException {
  104. JSONArray jsonArray = content.getJSONArray("itemnos");
  105. ERPDocking erpDocking = new ERPDocking();
  106. JSONArray rows = erpDocking.getErpIcinvbalBatchRows(1000, 1, jsonArray);
  107. return getSucReturnObject().setData(rows).toString();
  108. }
  109. @API(title = "新建或修改发货单商品明细", apiversion = R.ID20221115104603.v1.class)
  110. @CACHEING_CLEAN(apiClass = {dispatchItems.class, dispatch.class})
  111. public String insertormodify_dispatchItems() throws YosException {
  112. Long sa_dispatchid = content.getLong("sa_dispatchid");
  113. JSONArray iteminfos = content.getJSONArray("iteminfos");
  114. ArrayList<String> sqlList = new ArrayList<>();
  115. Rows rowscount = dbConnect.runSqlQuery("select billno,status from sa_dispatch where sa_dispatchid=" + sa_dispatchid);
  116. if (!rowscount.isEmpty()) {
  117. if (!rowscount.get(0).getString("status").equals("新建")) {
  118. return getErrReturnObject().setErrMsg("非新建状态的发货单无法新增修改").toString();
  119. }
  120. }
  121. int i = 0;
  122. long maxid = 0;
  123. long[] sa_dispatch_itemsid = createTableID("sa_dispatch_items", iteminfos.size());
  124. Rows maxidRows = dbConnect
  125. .runSqlQuery("select MAX(rowno) rowno from sa_dispatch_items where sa_dispatchid=" + sa_dispatchid);
  126. if (!maxidRows.isEmpty()) {
  127. maxid = maxidRows.get(0).getLong("rowno");
  128. }
  129. for (Object obj : iteminfos) {
  130. JSONObject iteminfo = (JSONObject) obj;
  131. if (iteminfo.getLong("sa_dispatch_itemsid") <= 0 || dbConnect
  132. .runSqlQuery("select sa_dispatch_itemsid from sa_dispatch_items where sa_dispatch_itemsid="
  133. + iteminfo.getLong("sa_dispatch_itemsid"))
  134. .isEmpty()) {
  135. Rows sa_dispatch_itemsrows = dbConnect.runSqlQuery("select sa_dispatch_itemsid,qty,remarks from sa_dispatch_items where sa_dispatchid="
  136. + sa_dispatchid + " and sa_orderitemsid=" + iteminfo.getLong("sa_orderitemsid"));
  137. if (!sa_dispatch_itemsrows.isEmpty()) {
  138. SQLFactory saleFactory = new SQLFactory(this, "发货单明细更新");
  139. saleFactory.addParameter("sa_dispatch_itemsid", sa_dispatch_itemsrows.get(0).getLong("sa_dispatch_itemsid"));
  140. // saleFactory.addParameter("itemno", iteminfo.getString("itemno"));
  141. saleFactory.addParameter("qty", iteminfo.getBigDecimal("qty").add(sa_dispatch_itemsrows.get(0).getBigDecimal("qty")));
  142. if (!StringUtils.isBlank(iteminfo.getString("remarks"))) {
  143. saleFactory.addParameter("remarks", iteminfo.getString("remarks"));
  144. } else {
  145. saleFactory.addParameter("remarks", sa_dispatch_itemsrows.get(0).getString("remarks"));
  146. }
  147. saleFactory.addParameter("userid", userid);
  148. saleFactory.addParameter("username", username);
  149. saleFactory.addParameter("billno", rowscount.get(0).getString("billno"));
  150. sqlList.add(saleFactory.getSQL());
  151. } else {
  152. SQLFactory saleFactory = new SQLFactory(this, "发货单明细新增");
  153. saleFactory.addParameter("siteid", siteid);
  154. saleFactory.addParameter("rowno", maxid + i + 1);
  155. saleFactory.addParameter("sa_dispatch_itemsid", sa_dispatch_itemsid[i]);
  156. saleFactory.addParameter("sa_dispatchid", sa_dispatchid);
  157. saleFactory.addParameter("sa_orderitemsid", iteminfo.getLong("sa_orderitemsid"));
  158. saleFactory.addParameter("itemid", iteminfo.getString("itemid"));
  159. saleFactory.addParameter("qty", iteminfo.getBigDecimal("qty"));
  160. saleFactory.addParameter("batchcontrol", iteminfo.getBooleanValue("batchcontrol"));
  161. saleFactory.addParameter("batchno", "");
  162. saleFactory.addParameter("remarks", iteminfo.getString("remarks"));
  163. saleFactory.addParameter("userid", userid);
  164. saleFactory.addParameter("username", username);
  165. saleFactory.addParameter("billno", rowscount.get(0).getString("billno"));
  166. sqlList.add(saleFactory.getSQL());
  167. }
  168. i++;
  169. } else {
  170. SQLFactory saleFactory = new SQLFactory(this, "发货单明细更新");
  171. saleFactory.addParameter("sa_dispatch_itemsid", iteminfo.getLong("sa_dispatch_itemsid"));
  172. // saleFactory.addParameter("itemno", iteminfo.getString("itemno"));
  173. saleFactory.addParameter("qty", iteminfo.getBigDecimal("qty"));
  174. saleFactory.addParameter("remarks", iteminfo.getString("remarks"));
  175. saleFactory.addParameter("batchno", iteminfo.getString("batchno"));
  176. saleFactory.addParameter("userid", userid);
  177. saleFactory.addParameter("username", username);
  178. saleFactory.addParameter("billno", rowscount.get(0).getString("billno"));
  179. sqlList.add(saleFactory.getSQL());
  180. }
  181. }
  182. dbConnect.runSqlUpdate(sqlList);
  183. return queryDispatchItemsList();
  184. }
  185. @API(title = "发货单商品明细列表", apiversion = R.ID20221115104703.v1.class)
  186. @CACHEING
  187. public String queryDispatchItemsList() throws YosException {
  188. /*
  189. * 过滤条件设置
  190. */
  191. StringBuffer where = new StringBuffer(" 1=1 ");
  192. if (content.containsKey("where")) {
  193. JSONObject whereObject = content.getJSONObject("where");
  194. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  195. where.append(" and(");
  196. where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  197. where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
  198. where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
  199. where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  200. where.append(")");
  201. }
  202. }
  203. Long sa_dispatchid = content.getLong("sa_dispatchid");
  204. // String hrid = content.getString("hrid");
  205. SQLFactory sqlFactory = new SQLFactory(this, "发货单明细列表查询", pageSize, pageNumber, pageSorting);
  206. sqlFactory.addParameter_SQL("where", where);
  207. sqlFactory.addParameter("sa_dispatchid", sa_dispatchid);
  208. sqlFactory.addParameter("siteid", siteid);
  209. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  210. RowsMap rowsMap = rows.toRowsMap("itemno");
  211. ERPDocking erpDocking = new ERPDocking();
  212. JSONArray jsonArray = new JSONArray();
  213. if (rows.toJsonArray("itemno").size() != 0) {
  214. if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
  215. jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, rows.toJsonArray("itemno"));
  216. }
  217. }
  218. SQLFactory sqlFactory1 = new SQLFactory(this, "商品发货数量汇总");
  219. sqlFactory1.addParameter("siteid", siteid);
  220. Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
  221. RowsMap sumQtyRowsMap = sumQtyRows.toRowsMap("itemno");
  222. if (!jsonArray.isEmpty()) {
  223. for (Object object : jsonArray) {
  224. JSONObject jsonObject = (JSONObject) object;
  225. if (rowsMap.containsKey(jsonObject.getString("fitemno"))) {
  226. if (rowsMap.get(jsonObject.getString("fitemno")).isNotEmpty()) {
  227. if (sumQtyRowsMap.containsKey(jsonObject.getString("fitemno"))) {
  228. rowsMap.get(jsonObject.getString("fitemno")).get(0).put("delinvbalqty", jsonObject.getBigDecimalValue("fqty").subtract(sumQtyRowsMap.get(jsonObject.getString("fitemno")).get(0).getBigDecimal("qty")));
  229. } else {
  230. rowsMap.get(jsonObject.getString("fitemno")).get(0).put("delinvbalqty", jsonObject.getBigDecimalValue("fqty"));
  231. }
  232. rowsMap.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
  233. }
  234. }
  235. }
  236. }
  237. for (Row row : rows) {
  238. if (!row.containsKey("delinvbalqty")) {
  239. row.put("delinvbalqty", row.getBigDecimal("undeliqty").negate());
  240. row.put("invbalqty", 0);
  241. }
  242. }
  243. return getSucReturnObject().setData(rows).toString();
  244. }
  245. @API(title = "发货单商品所有明细列表", apiversion = R.ID20230508113003.v1.class)
  246. @CACHEING
  247. public String queryDispatchAllItemsList() throws YosException, IOException {
  248. /*
  249. * 过滤条件设置
  250. */
  251. StringBuffer where = new StringBuffer(" 1=1 ");
  252. if (sys_enterpriseid > 0) {
  253. where.append(" and t4.sys_enterpriseid ='").append(sys_enterpriseid).append("' ");
  254. }
  255. if (content.containsKey("where")) {
  256. JSONObject whereObject = content.getJSONObject("where");
  257. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  258. where.append(" and(");
  259. where.append(" t4.billno like'%").append(whereObject.getString("condition")).append("%' ");
  260. where.append("or t8.sonum like'%").append(whereObject.getString("condition")).append("%' ");
  261. where.append("or t9.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
  262. where.append("or t10.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  263. where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  264. where.append("or t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  265. where.append(")");
  266. }
  267. if (whereObject.containsKey("agentinfo") && !"".equals(whereObject.getString("agentinfo"))) {
  268. where.append(" and(");
  269. where.append("t9.agentnum like'%").append(whereObject.getString("agentinfo")).append("%' ");
  270. where.append("or t10.enterprisename like'%").append(whereObject.getString("agentinfo")).append("%' ");
  271. where.append(")");
  272. }
  273. if (whereObject.containsKey("iteminfo") && !"".equals(whereObject.getString("iteminfo"))) {
  274. where.append(" and(");
  275. where.append("t2.itemno like'%").append(whereObject.getString("iteminfo")).append("%' ");
  276. where.append("or t2.itemname like'%").append(whereObject.getString("iteminfo")).append("%' ");
  277. where.append(")");
  278. }
  279. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  280. where.append(" and t4.billdate >='").append(whereObject.getString("begindate")).append("' ");
  281. }
  282. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  283. where.append(" and t4.billdate <='").append(whereObject.getString("enddate")).append("' ");
  284. }
  285. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  286. where.append(" and t4.status ='").append(whereObject.getString("status")).append("' ");
  287. }
  288. if (whereObject.containsKey("isnotsent") && !"".equals(whereObject.getString("isnotsent"))) {
  289. if(whereObject.getBooleanValue("isnotsent")){
  290. //System.out.println(" and t4.status ='复核' and ifnull(t1.outwarehouseqty, 0)< ifnull(t1.qty, 0)");
  291. where.append(" and ifnull(t1.qty, 0)> ifnull(t1.outwarehouseqty, 0) and t1.sa_dispatchid in(select t1.sa_dispatchid from sa_dispatch_items t1 LEFT JOIN sa_dispatch t4 ON t4.sa_dispatchid = t1.sa_dispatchid AND t4.siteid = t1.siteid where t4.status ='复核' and ifnull(t1.outwarehouseqty, 0)< ifnull(t1.qty, 0) and ifnull(t1.outwarehouseqty, 0)>0)");
  292. }
  293. }
  294. }
  295. boolean isExport = content.getBooleanValue("isExport");
  296. SQLFactory sqlFactory = new SQLFactory(this, "发货单明细所有列表查询", pageSize, pageNumber, pageSorting);
  297. if (isExport) {
  298. sqlFactory = new SQLFactory(this, "发货单明细所有列表查询");
  299. }
  300. sqlFactory.addParameter_SQL("where", where);
  301. sqlFactory.addParameter("siteid", siteid);
  302. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  303. RowsMap rowsMap = rows.toRowsMap("itemno");
  304. ERPDocking erpDocking = new ERPDocking();
  305. JSONArray jsonArray = new JSONArray();
  306. if (rows.toJsonArray("itemno").size() != 0) {
  307. if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
  308. jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, rows.toJsonArray("itemno"));
  309. }
  310. }
  311. SQLFactory sqlFactory1 = new SQLFactory(this, "商品发货数量汇总");
  312. sqlFactory1.addParameter("siteid", siteid);
  313. Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
  314. RowsMap sumQtyRowsMap = sumQtyRows.toRowsMap("itemno");
  315. if (!jsonArray.isEmpty()) {
  316. for (Object object : jsonArray) {
  317. JSONObject jsonObject = (JSONObject) object;
  318. if (rowsMap.containsKey(jsonObject.getString("fitemno"))) {
  319. if (rowsMap.get(jsonObject.getString("fitemno")).isNotEmpty()) {
  320. if (sumQtyRowsMap.containsKey(jsonObject.getString("fitemno"))) {
  321. rowsMap.get(jsonObject.getString("fitemno")).get(0).put("delinvbalqty", jsonObject.getBigDecimalValue("fqty").subtract(sumQtyRowsMap.get(jsonObject.getString("fitemno")).get(0).getBigDecimal("qty")));
  322. } else {
  323. rowsMap.get(jsonObject.getString("fitemno")).get(0).put("delinvbalqty", jsonObject.getBigDecimalValue("fqty"));
  324. }
  325. rowsMap.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
  326. }
  327. }
  328. }
  329. }
  330. for (Row row : rows) {
  331. if (!row.containsKey("delinvbalqty")) {
  332. row.put("delinvbalqty", row.getBigDecimal("undeliqty").negate());
  333. row.put("invbalqty", 0);
  334. }
  335. }
  336. if (isExport) {
  337. ExcelFactory excelFactory = new ExcelFactory("发货单明细所有列表");
  338. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
  339. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  340. CellStyle style = xssfFWorkbook.createCellStyle();
  341. // 设置为文本格式,防止身份证号变成科学计数法
  342. DataFormat format = xssfFWorkbook.createDataFormat();
  343. style.setDataFormat(format.getFormat("@"));
  344. // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
  345. sheet.setDefaultColumnStyle(0, style);
  346. ExportDown.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  347. XSSFCellStyle titleCellStyle2 = ExportDown.createTitleCellStyle2(xssfFWorkbook);
  348. XSSFCellStyle titleCellStyle3 = ExportDown.createBodyCellStyle(xssfFWorkbook);
  349. ExportDown.batchDetail(sheet, titleCellStyle2, titleCellStyle3, rows);// 写入标题
  350. Rows uploadRows = uploadExcelToObs(excelFactory);
  351. String url = "";
  352. if (!uploadRows.isEmpty()) {
  353. url = uploadRows.get(0).getString("url");
  354. }
  355. return getSucReturnObject().setData(url).toString();
  356. }
  357. return getSucReturnObject().setData(rows).toString();
  358. }
  359. //返回导出的标题
  360. public HashMap<String, String> getTitleMap() {
  361. HashMap<String, String> titleMap = new HashMap<>();
  362. titleMap.put("billno", "发货单号");
  363. titleMap.put("status", "状态");
  364. titleMap.put("sonum", "订单号");
  365. titleMap.put("enterprisename", "企业名称");
  366. titleMap.put("agentnum", "经销商编号");
  367. titleMap.put("billdate", "发货日期");
  368. titleMap.put("orderRowno", "订单行号");
  369. titleMap.put("itemno", "产品编码");
  370. titleMap.put("itemname", "品名");
  371. titleMap.put("unitname", "单位");
  372. titleMap.put("qty", "发货数量");
  373. titleMap.put("remarks", "发货行备注");
  374. return titleMap;
  375. }
  376. @API(title = "删除明细", apiversion = R.ID20221115104803.v1.class)
  377. @CACHEING_CLEAN(apiClass = {dispatchItems.class, dispatch.class})
  378. public String deletemx() throws YosException {
  379. JSONArray sa_dispatch_itemsids = content.getJSONArray("sa_dispatch_itemsids");
  380. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_dispatch_itemsids.size());
  381. long sa_dispatchid = 0;
  382. for (Object o : sa_dispatch_itemsids) {
  383. long sa_dispatch_itemsid = Long.parseLong(o.toString());
  384. Rows RowsStatus = dbConnect.runSqlQuery("select t1.sa_dispatch_itemsid,t2.status,t1.sa_dispatchid from sa_dispatch_items t1 left join sa_dispatch t2 on t1.sa_dispatchid=t2.sa_dispatchid and t1.siteid=t2.siteid where t1.siteid='"
  385. + siteid + "' and t1.sa_dispatch_itemsid='" + sa_dispatch_itemsid + "'");
  386. if (RowsStatus.isNotEmpty()) {
  387. sa_dispatchid = RowsStatus.get(0).getLong("sa_dispatchid");
  388. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  389. batchDeleteErr.addErr(sa_dispatch_itemsid, "非新建状态的发货单明细无法删除");
  390. continue;
  391. }
  392. }
  393. ArrayList<String> list = new ArrayList<>();
  394. SQLFactory deletesql = new SQLFactory("sql:delete from sa_dispatch_items where siteid='" + siteid
  395. + "' and sa_dispatch_itemsid=" + sa_dispatch_itemsid);
  396. list.add(deletesql.getSQL());
  397. dbConnect.runSqlUpdate(list);
  398. }
  399. //重新排序
  400. updateRowNo(sa_dispatchid);
  401. return batchDeleteErr.getReturnObject().toString();
  402. }
  403. /**
  404. * 重新对发货单行进行排序
  405. *
  406. * @param
  407. * @throws YosException
  408. */
  409. public void updateRowNo(Long sa_dispatchid) throws YosException {
  410. String sql = "SELECT sa_dispatch_itemsid from sa_dispatch_items WHERE sa_dispatchid= " + sa_dispatchid + " and siteid = '" + siteid + "' ORDER BY sa_dispatch_itemsid asc ";
  411. ArrayList<Long> sa_dispatch_itemsids = dbConnect.runSqlQuery(sql).toArrayList("sa_dispatch_itemsid", new ArrayList<>());
  412. ArrayList<String> sqlList = new ArrayList<>();
  413. int rowno = 1;
  414. for (Long id : sa_dispatch_itemsids) {
  415. sqlList.add("UPDATE sa_dispatch_items SET rowno=" + rowno + " WHERE sa_dispatch_itemsid = " + id);
  416. rowno++;
  417. }
  418. dbConnect.runSqlUpdate(sqlList);
  419. }
  420. }