sendrepair_pj.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. package restcontroller.webmanage.sale.sendrepair;
  2. import beans.data.BatchDeleteErr;
  3. import beans.itemprice.ItemPrice;
  4. import com.alibaba.fastjson2.JSONArray;
  5. import com.alibaba.fastjson2.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 restcontroller.R;
  13. import java.util.ArrayList;
  14. import java.util.HashMap;
  15. @API(title = "送修单配件")
  16. public class sendrepair_pj extends Controller {
  17. public sendrepair_pj(JSONObject content) throws YosException {
  18. super(content);
  19. }
  20. @API(title = "送修配件列表查询", apiversion = R.ID2025070414582703.v1.class)
  21. @CACHEING
  22. public String queryOrderItemgList() throws YosException {
  23. long sa_sendrepairid=content.getLong("sa_sendrepairid");
  24. Rows sendrepairrows =dbConnect.runSqlQuery("select sys_enterpriseid from sa_sendrepair where sa_sendrepairid="+sa_sendrepairid);
  25. if(sendrepairrows.isEmpty()){
  26. return getErrReturnObject().setErrMsg("送修单不存在").toString();
  27. }
  28. sys_enterpriseid=sendrepairrows.get(0).getLong("sys_enterpriseid");
  29. /*
  30. * 过滤条件设置
  31. */
  32. StringBuffer where = new StringBuffer(" 1=1 ");
  33. if (content.containsKey("where")) {
  34. JSONObject whereObject = content.getJSONObject("where");
  35. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  36. where.append(" and(");
  37. where.append("t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  38. where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  39. where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
  40. where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
  41. where.append(")");
  42. }
  43. }
  44. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item", "*");
  45. querySQL.setTableAlias("t1");
  46. querySQL.setSiteid(siteid);
  47. querySQL.setWhere("isused=1 and status='审核' and ismodule=1");
  48. querySQL.setWhere("t1.itemid not in (select itemid from sa_sendrepair_pj where sa_sendrepairid='"+content.getLongValue("sa_sendrepairid")+"')");
  49. querySQL.setWhere(where.toString());
  50. querySQL.setPage(pageSize, pageNumber);
  51. Rows rows = querySQL.query();
  52. HashMap<Long, ItemPrice> itemPriceRowsMap = ItemPrice.getItemPrice(this, sys_enterpriseid,rows.toArrayList("itemid", new ArrayList<>()));
  53. for (Row row :rows){
  54. if (itemPriceRowsMap.containsKey(row.getLong("itemid"))) {
  55. row.put("price", itemPriceRowsMap.get(row.getLong("itemid")).getPrice());
  56. } else {
  57. row.put("price", 0);
  58. }
  59. }
  60. return getSucReturnObject().setData(rows).toString();
  61. }
  62. @API(title = "送修单明细新增更新", apiversion = R.ID2025070414583703.v1.class)
  63. @CACHEING_CLEAN(apiClass = {sendrepair.class, sendrepair_pj.class})
  64. public String insertormodify_sendrepairpjs() throws YosException {
  65. Long sa_sendrepairid = content.getLong("sa_sendrepairid");
  66. JSONArray iteminfos = content.getJSONArray("iteminfos");
  67. ArrayList<String> sqlList = new ArrayList<>();
  68. Rows rowscount = dbConnect.runSqlQuery("select billno,status from sa_sendrepair where sa_sendrepairid=" + sa_sendrepairid);
  69. if (!rowscount.isEmpty()) {
  70. if (rowscount.get(0).getString("status").equals("审核") || rowscount.get(0).getString("status").equals("退款确认")) {
  71. return getErrReturnObject().setErrMsg("审核或退款确认状态的送修单无法新增修改").toString();
  72. }
  73. }
  74. int i = 0;
  75. long maxid = 0;
  76. long[] sa_sendrepair_pjid = createTableID("sa_sendrepair_pj", iteminfos.size());
  77. for (Object obj : iteminfos) {
  78. JSONObject iteminfo = (JSONObject) obj;
  79. if (iteminfo.getLong("sa_sendrepair_pjid") <= 0 || dbConnect
  80. .runSqlQuery("select sa_sendrepair_pjid from sa_sendrepair_pj where sa_sendrepair_pjid="
  81. + iteminfo.getLong("sa_sendrepair_pjid"))
  82. .isEmpty()) {
  83. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_sendrepair_pj");
  84. insertSQL.setUniqueid(sa_sendrepair_pjid[i]);
  85. insertSQL.setSiteid(siteid);
  86. insertSQL.setValue("sa_sendrepairid", sa_sendrepairid);
  87. insertSQL.setValue("itemid", iteminfo.getStringValue("itemid"));
  88. insertSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
  89. insertSQL.setValue("price", iteminfo.getBigDecimal("price"));
  90. insertSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
  91. i++;
  92. sqlList.add(insertSQL.getSQL());
  93. } else {
  94. Rows rows = dbConnect.runSqlQuery(
  95. "SELECT status from sa_sendrepair WHERE sa_sendrepairid = "
  96. + sa_sendrepairid);
  97. if (rows.isNotEmpty()) {
  98. if (rows.get(0).getString("status").equals("新建")) {
  99. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair_pj");
  100. updateSQL.setUniqueid(iteminfo.getLong("sa_sendrepair_pjid"));
  101. updateSQL.setSiteid(siteid);
  102. updateSQL.setValue("itemid", iteminfo.getString("itemid"));
  103. updateSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
  104. updateSQL.setValue("price", iteminfo.getBigDecimal("price"));
  105. updateSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
  106. sqlList.add(updateSQL.getSQL());
  107. } else {
  108. return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
  109. }
  110. } else {
  111. return getErrReturnObject().setErrMsg("该送修单不存在").toString();
  112. }
  113. }
  114. }
  115. dbConnect.runSqlUpdate(sqlList);
  116. return quersendrepairpjsList();
  117. }
  118. @API(title = "送修单配件列表", apiversion = R.ID2025070414584903.v1.class)
  119. @CACHEING
  120. public String quersendrepairpjsList() throws YosException {
  121. /*
  122. * 过滤条件设置
  123. */
  124. StringBuffer where = new StringBuffer(" 1=1 ");
  125. if (content.containsKey("where")) {
  126. JSONObject whereObject = content.getJSONObject("where");
  127. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  128. where.append(" and(");
  129. where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
  130. where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
  131. where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
  132. where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
  133. where.append(")");
  134. }
  135. }
  136. Long sa_sendrepairid = content.getLong("sa_sendrepairid");
  137. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendrepair_pj", "*");
  138. querySQL.setTableAlias("t1");
  139. querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid = t2.itemid AND t1.siteid = t2.siteid","itemname","itemno","spec","model");
  140. querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t3", "t2.unitid = t3.unitid AND t2.siteid = t3.siteid","unitname");
  141. querySQL.setSiteid(siteid);
  142. querySQL.setWhere("t1.sa_sendrepairid",sa_sendrepairid);
  143. querySQL.setWhere(where.toString());
  144. querySQL.setPage(pageSize, pageNumber);
  145. Rows rows = querySQL.query();
  146. return getSucReturnObject().setData(rows).toString();
  147. }
  148. @API(title = "删除明细", apiversion = R.ID2025070414590403.v1.class)
  149. @CACHEING_CLEAN(apiClass = {sendrepair.class, sendrepair_pj.class})
  150. public String deletemx() throws YosException {
  151. JSONArray sa_sendrepair_pjids = content.getJSONArray("sa_sendrepair_pjids");
  152. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_sendrepair_pjids.size());
  153. long sa_sendrepairid = 0;
  154. for (Object o : sa_sendrepair_pjids) {
  155. long sa_sendrepair_pjid = Long.parseLong(o.toString());
  156. Rows RowsStatus = dbConnect.runSqlQuery("select t1.sa_sendrepair_pjid,t2.status,t1.sa_sendrepairid from sa_sendrepair_pj t1 left join sa_sendrepair t2 on t1.sa_sendrepairid=t2.sa_sendrepairid and t1.siteid=t2.siteid where t1.siteid='"
  157. + siteid + "' and t1.sa_sendrepair_pjid='" + sa_sendrepair_pjid + "'");
  158. if (RowsStatus.isNotEmpty()) {
  159. sa_sendrepairid = RowsStatus.get(0).getLong("sa_sendrepairid");
  160. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  161. batchDeleteErr.addErr(sa_sendrepair_pjid, "非新建状态的送修单明细无法删除");
  162. continue;
  163. }
  164. }
  165. ArrayList<String> list = new ArrayList<>();
  166. list.add("delete from sa_sendrepair_pj where siteid='" + siteid
  167. + "' and sa_sendrepair_pjid=" + sa_sendrepair_pjid);
  168. dbConnect.runSqlUpdate(list);
  169. }
  170. return batchDeleteErr.getReturnObject().toString();
  171. }
  172. }