dbstockbilldetail.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package restcontroller.webmanage.sale.dbstockbill;
  2. import beans.data.BatchDeleteErr;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.annotation.CACHEING;
  9. import common.annotation.CACHEING_CLEAN;
  10. import common.data.*;
  11. import restcontroller.R;
  12. import java.math.BigDecimal;
  13. import java.util.ArrayList;
  14. public class dbstockbilldetail extends Controller {
  15. public dbstockbilldetail(JSONObject content) throws YosException {
  16. super(content);
  17. }
  18. @API(title = "出库商品列表查询", apiversion = R.ID2025061915091103.v1.class)
  19. @CACHEING
  20. public String queryOrderItemgList() throws YosException {
  21. StringBuffer where = new StringBuffer(" 1=1 ");
  22. if (content.containsKey("where")) {
  23. JSONObject whereObject = content.getJSONObject("where");
  24. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  25. where.append(" and(");
  26. where.append("t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  27. where.append("or t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  28. where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
  29. where.append(")");
  30. }
  31. }
  32. SQLFactory sqlFactory;
  33. QuerySQL querySQL;
  34. querySQL = SQLFactory.createQuerySQL(this, "st_invbal", "*");
  35. querySQL.setTableAlias("t1");
  36. querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid = t2.itemid AND t1.siteid = t2.siteid","itemno","itemname","model","spec");
  37. querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t3", "t1.stockid = t3.stockid AND t1.siteid = t3.siteid","stockno","stockname");
  38. querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t4", "t4.unitid = t2.unitid AND t4.siteid = t2.siteid","unitname");
  39. querySQL.setSiteid(siteid);
  40. querySQL.setWhere(where.toString());
  41. querySQL.setWhere("t1.stockid",content.getLongValue("stockid"));
  42. querySQL.setPage(pageSize, pageNumber);
  43. querySQL.setOrderBy(pageSorting);
  44. Rows rows = querySQL.query();
  45. return getSucReturnObject().setData(rows).toString();
  46. }
  47. @API(title = "调拨单明细新增更新", apiversion = R.ID2025061915092903.v1.class)
  48. @CACHEING_CLEAN(apiClass = {dbstockbill.class, dbstockbilldetail.class})
  49. public String insertormodify_dbstcokbillItems() throws YosException {
  50. Long st_dbstockbillid = content.getLong("st_dbstockbillid");
  51. JSONArray iteminfos = content.getJSONArray("iteminfos");
  52. ArrayList<String> sqlList = new ArrayList<>();
  53. Rows rowscount = dbConnect.runSqlQuery("select billno,status,outstockid,instockid from st_dbstockbill where st_dbstockbillid=" + st_dbstockbillid);
  54. if (!rowscount.isEmpty()) {
  55. if (!rowscount.get(0).getString("status").equals("新建")) {
  56. return getErrReturnObject().setErrMsg("非新建状态的调拨单无法新增修改").toString();
  57. }
  58. }else{
  59. return getErrReturnObject().setErrMsg("调拨单不存在").toString();
  60. }
  61. int i = 0;
  62. long maxid = 0;
  63. long[] st_dbstockbilldetailid = createTableID("st_dbstockbilldetail", iteminfos.size());
  64. Rows maxidRows = dbConnect
  65. .runSqlQuery("select MAX(rowno) rowno from st_dbstockbilldetail where st_dbstockbillid=" + st_dbstockbillid);
  66. if (!maxidRows.isEmpty()) {
  67. maxid = maxidRows.get(0).getLong("rowno");
  68. }
  69. for (Object obj : iteminfos) {
  70. JSONObject iteminfo = (JSONObject) obj;
  71. if (iteminfo.getLong("st_dbstockbilldetailid") <= 0 || dbConnect
  72. .runSqlQuery("select st_dbstockbilldetailid from st_dbstockbilldetail where st_dbstockbilldetailid="
  73. + iteminfo.getLong("st_dbstockbilldetailid"))
  74. .isEmpty()) {
  75. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_dbstockbilldetail");
  76. insertSQL.setUniqueid(st_dbstockbilldetailid[i]);
  77. insertSQL.setSiteid(siteid);
  78. insertSQL.setValue("rowno", maxid + i + 1);
  79. insertSQL.setValue("st_dbstockbillid", st_dbstockbillid);
  80. insertSQL.setValue("outstockid", rowscount.get(0).getLong("outstockid"));
  81. insertSQL.setValue("instockid",rowscount.get(0).getLong("instockid"));
  82. insertSQL.setValue("itemid", iteminfo.getLongValue("itemid"));
  83. insertSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
  84. insertSQL.setValue("undeliqty", iteminfo.getBigDecimal("qty"));
  85. insertSQL.setValue("remarks", iteminfo.getStringValue("remarks"));
  86. i++;
  87. sqlList.add(insertSQL.getSQL());
  88. } else {
  89. Rows rows = dbConnect.runSqlQuery(
  90. "SELECT status from st_dbstockbill WHERE st_dbstockbillid = "
  91. + st_dbstockbillid);
  92. if (rows.isNotEmpty()) {
  93. if (rows.get(0).getString("status").equals("新建")) {
  94. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_dbstockbilldetail");
  95. updateSQL.setUniqueid(iteminfo.getLong("st_dbstockbilldetailid"));
  96. updateSQL.setSiteid(siteid);
  97. updateSQL.setValue("itemid", iteminfo.getLongValue("itemid"));
  98. updateSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
  99. updateSQL.setValue("undeliqty", iteminfo.getBigDecimal("qty"));
  100. updateSQL.setValue("remarks", iteminfo.getStringValue("remarks"));
  101. sqlList.add(updateSQL.getSQL());
  102. } else {
  103. return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
  104. }
  105. } else {
  106. return getErrReturnObject().setErrMsg("该销售调拨单不存在").toString();
  107. }
  108. }
  109. }
  110. dbConnect.runSqlUpdate(sqlList);
  111. return querStcokbillItemsList();
  112. }
  113. @API(title = "调拨单明细列表", apiversion = R.ID2025061915094203.v1.class)
  114. @CACHEING
  115. public String querStcokbillItemsList() throws YosException {
  116. /*
  117. * 过滤条件设置
  118. */
  119. StringBuffer where = new StringBuffer(" 1=1 ");
  120. if (content.containsKey("where")) {
  121. JSONObject whereObject = content.getJSONObject("where");
  122. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  123. where.append(" and(");
  124. where.append("t4.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  125. where.append("or t4.model like'%").append(whereObject.getString("condition")).append("%' ");
  126. where.append("or t4.spec like'%").append(whereObject.getString("condition")).append("%' ");
  127. where.append("or t4.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  128. where.append(")");
  129. }
  130. }
  131. Long st_dbstockbillid = content.getLong("st_dbstockbillid");
  132. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_dbstockbilldetail","*");
  133. querySQL.setTableAlias("t1");
  134. querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t2", "t1.instockid = t2.stockid AND t1.siteid = t2.siteid");
  135. querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t3", "t1.outstockid = t3.stockid AND t1.siteid = t3.siteid");
  136. querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t4", "t1.itemid=t4.itemid and t1.siteid = t4.siteid","itemno","itemname"
  137. ,"spec","model");
  138. querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t5", "t4.unitid=t5.unitid and t4.siteid = t5.siteid","unitname");
  139. querySQL.addQueryFields("outstockno", "t3.stockno");
  140. querySQL.addQueryFields("outstockname", "t3.stockname");
  141. querySQL.addQueryFields("instockno", "t2.stockno");
  142. querySQL.addQueryFields("instockname", "t2.stockname");
  143. querySQL.setWhere("t1.siteid", siteid);
  144. querySQL.setWhere(where);
  145. querySQL.setWhere("t1.st_dbstockbillid",st_dbstockbillid);
  146. querySQL.setPage(pageSize, pageNumber);
  147. querySQL.setOrderBy(pageSorting);
  148. Rows rows = querySQL.query();
  149. return getSucReturnObject().setData(rows).toString();
  150. }
  151. @API(title = "删除明细", apiversion = R.ID2025061915102603.v1.class)
  152. @CACHEING_CLEAN(apiClass = {dbstockbill.class, dbstockbilldetail.class})
  153. public String deletemx() throws YosException {
  154. JSONArray st_dbstockbilldetailids = content.getJSONArray("st_dbstockbilldetailids");
  155. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, st_dbstockbilldetailids.size());
  156. long st_dbstockbillid = 0;
  157. for (Object o : st_dbstockbilldetailids) {
  158. long st_dbstockbilldetailid = Long.parseLong(o.toString());
  159. Rows RowsStatus = dbConnect.runSqlQuery("select t1.st_dbstockbilldetailid,t2.status,t1.st_dbstockbillid from st_dbstockbilldetail t1 left join st_dbstockbill t2 on t1.st_dbstockbillid=t2.st_dbstockbillid and t1.siteid=t2.siteid where t1.siteid='"
  160. + siteid + "' and t1.st_dbstockbilldetailid='" + st_dbstockbilldetailid + "'");
  161. if (RowsStatus.isNotEmpty()) {
  162. st_dbstockbillid = RowsStatus.get(0).getLong("st_dbstockbillid");
  163. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  164. batchDeleteErr.addErr(st_dbstockbilldetailid, "非新建状态的调拨单明细无法删除");
  165. continue;
  166. }
  167. }
  168. ArrayList<String> list = new ArrayList<>();
  169. list.add("delete from st_dbstockbilldetail where siteid='" + siteid
  170. + "' and st_dbstockbilldetailid=" + st_dbstockbilldetailid);
  171. list.add("delete from st_dbstockbilldetailsku where siteid='" + siteid
  172. + "' and st_dbstockbilldetailid=" + st_dbstockbilldetailid);
  173. dbConnect.runSqlUpdate(list);
  174. }
  175. //重新排序
  176. updateRowNo(st_dbstockbillid);
  177. return batchDeleteErr.getReturnObject().toString();
  178. }
  179. /**
  180. * 重新将行进行排序
  181. *
  182. * @param
  183. * @throws YosException
  184. */
  185. public void updateRowNo(Long st_dbstockbillid) throws YosException {
  186. String sql = "SELECT st_dbstockbilldetailid from st_dbstockbilldetail WHERE st_dbstockbillid= " + st_dbstockbillid + " and siteid = '" + siteid + "' ORDER BY st_dbstockbilldetailid asc ";
  187. ArrayList<Long> st_dbstockbilldetailids = dbConnect.runSqlQuery(sql).toArrayList("st_dbstockbilldetailid", new ArrayList<>());
  188. ArrayList<String> sqlList = new ArrayList<>();
  189. int rowno = 1;
  190. for (Long id : st_dbstockbilldetailids) {
  191. sqlList.add("UPDATE st_dbstockbilldetail SET rowno=" + rowno + " WHERE st_dbstockbilldetailid = " + id);
  192. rowno++;
  193. }
  194. dbConnect.runSqlUpdate(sqlList);
  195. }
  196. }