sendrepair.java 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  1. package restcontroller.webmanage.sale.sendrepair;
  2. import beans.accountbalance.Accountbalance;
  3. import beans.accountbalance.CashbillEntity;
  4. import beans.data.BatchDeleteErr;
  5. import beans.datacontrllog.DataContrlLog;
  6. import com.alibaba.fastjson2.JSONArray;
  7. import com.alibaba.fastjson2.JSONObject;
  8. import common.Controller;
  9. import common.YosException;
  10. import common.annotation.API;
  11. import common.annotation.CACHEING;
  12. import common.annotation.CACHEING_CLEAN;
  13. import common.data.*;
  14. import org.apache.commons.lang.StringUtils;
  15. import restcontroller.R;
  16. import java.math.BigDecimal;
  17. import java.util.ArrayList;
  18. @API(title = "送修单")
  19. public class sendrepair extends Controller {
  20. public sendrepair(JSONObject content) throws YosException {
  21. super(content);
  22. }
  23. @API(title = "送修单更新", apiversion = R.ID2025070414202703.v1.class, intervaltime = 200)
  24. @CACHEING_CLEAN(apiClass = {sendrepair.class})
  25. public String insertormodify_sendrepair() throws YosException {
  26. ArrayList<String> sqlList = new ArrayList<>();
  27. // 表名
  28. String tableName = "sa_sendrepair";
  29. Long sa_sendrepairid = content.getLong("sa_sendrepairid");
  30. // String type = content.getString("type");
  31. // String typemx = content.getStringValue("typemx");
  32. // Long sa_orderid = content.getLong("sa_orderid");
  33. // BigDecimal rebate_userate =content.getBigDecimalValue("rebate_userate");
  34. // BigDecimal returnamount = content.getBigDecimalValue("returnamount");
  35. // Long sa_accountclassid = content.getLong("sa_accountclassid");
  36. // String reason = content.getStringValue("reason");
  37. // boolean isitemreturn = content.getBooleanValue("isitemreturn");
  38. //// String logisticno = content.getStringValue("logisticno");
  39. if (sa_sendrepairid > 0 && dbConnect.runSqlQuery(
  40. "select sa_sendrepairid from sa_sendrepair where sa_sendrepairid=" + sa_sendrepairid)
  41. .isNotEmpty()) {
  42. Rows rows = dbConnect.runSqlQuery(
  43. "SELECT status from sa_sendrepair WHERE sa_sendrepairid = "
  44. + sa_sendrepairid);
  45. if (rows.isNotEmpty()) {
  46. if (rows.get(0).getString("status").equals("新建")) {
  47. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
  48. updateSQL.setUniqueid(sa_sendrepairid);
  49. updateSQL.setSiteid(siteid);
  50. updateSQL.setValue("remarks", content.getStringValue("remarks"));
  51. updateSQL.setDateValue("changedate");
  52. sqlList.add(updateSQL.getSQL());
  53. sqlList.add(DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "更新", "送修单更新成功")
  54. .getSQL());
  55. } else {
  56. // return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
  57. }
  58. } else {
  59. return getErrReturnObject().setErrMsg("该送修单不存在").toString();
  60. }
  61. }
  62. Rows sendrepairdetailRows =dbConnect.runSqlQuery("select sa_sendrepair_detailid from sa_sendrepair_detail where siteid='"+siteid+"' and sa_sendrepairid="+sa_sendrepairid);
  63. if(sendrepairdetailRows.isEmpty()){
  64. return getErrReturnObject().setErrMsg("该送修单表体不存在").toString();
  65. }
  66. UpdateSQL UpdateSQLdetail = SQLFactory.createUpdateSQL(this, "sa_sendrepair_detail");
  67. UpdateSQLdetail.setUniqueid(sendrepairdetailRows.get(0).getLong("sa_sendrepair_detailid"));
  68. UpdateSQLdetail.setSiteid(siteid);
  69. UpdateSQLdetail.setValue("duty", content.getStringValue("duty"));
  70. UpdateSQLdetail.setValue("reason", content.getStringValue("reason"));
  71. UpdateSQLdetail.setValue("demand", content.getStringValue("demand"));
  72. UpdateSQLdetail.setValue("remarks", content.getStringValue("remarks"));
  73. UpdateSQLdetail.setValue("disposition", content.getStringValue("disposition"));
  74. UpdateSQLdetail.setValue("idearemarks", content.getStringValue("idearemarks"));
  75. UpdateSQLdetail.setValue("agentcost", content.getBigDecimal("agentcost"));
  76. UpdateSQLdetail.setValue("newitemid", content.getStringValue("newitemid"));
  77. UpdateSQLdetail.setValue("newitenmno", content.getStringValue("newitenmno"));
  78. UpdateSQLdetail.setValue("newitemname", content.getStringValue("newitemname"));
  79. UpdateSQLdetail.setValue("newspec", content.getStringValue("newspec"));
  80. UpdateSQLdetail.setValue("newsku", content.getStringValue("newsku"));
  81. sqlList.add(UpdateSQLdetail.getSQL());
  82. dbConnect.runSqlUpdate(sqlList);
  83. content.put("sa_sendrepairid", sa_sendrepairid);
  84. return querysendrepairMain();
  85. }
  86. @API(title = "送修单详情", apiversion = R.ID2025070414204203.v1.class)
  87. @CACHEING
  88. public String querysendrepairMain() throws YosException {
  89. Long sa_sendrepairid = content.getLong("sa_sendrepairid");
  90. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendrepair", "*");
  91. querySQL.setTableAlias("t1");
  92. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid","enterprisename");
  93. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid","agentnum");
  94. querySQL.addJoinTable(JOINTYPE.left, "sa_sendrepair_detail", "t4", "t1.sa_sendrepairid = t4.sa_sendrepairid AND t1.siteid = t4.siteid","newspec","newitemno","newitemname",
  95. "newitemid","newsku","agentcost","practicalamount","instockdate","amount","logisticscost","logistics","idearemarks","disposition","demand","reason","duty",
  96. "stockdate","enddate","phonenumber","name","qty","itemid","sku");
  97. querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t5", "t5.itemid = t4.itemid AND t5.siteid = t4.siteid","itemname","itemno","spec","model");
  98. querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t6", "t5.unitid = t6.unitid AND t5.siteid = t6.siteid","unitname");
  99. querySQL.addQueryFields("remarksdetail","t4.remarks");
  100. querySQL.setSiteid(siteid);
  101. querySQL.setWhere("t1.sa_sendrepairid",sa_sendrepairid);
  102. querySQL.setPage(pageSize, pageNumber);
  103. Rows rows = querySQL.query();
  104. return getSucReturnObject().setData(rows).toString();
  105. }
  106. @API(title = "查询送修单列表", apiversion = R.ID2025070414205403.v1.class)
  107. @CACHEING
  108. public String querysendrepairList() throws YosException {
  109. StringBuffer where = new StringBuffer(" 1=1 ");
  110. if (content.containsKey("where")) {
  111. JSONObject whereObject = content.getJSONObject("where");
  112. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  113. where.append(" and(");
  114. where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
  115. where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  116. where.append(")");
  117. }
  118. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  119. // if(content.getString("type").equals("借用归还单")) {
  120. // where.append(" and t1.createdate >='" + whereObject.getString("startdate")).append("' ");
  121. // }else if(content.getString("type").equals("退货单")) {
  122. // where.append(" and t1.checkdate >='" + whereObject.getString("startdate")).append("' ");
  123. // }
  124. where.append(" and t1.billdate >='" + whereObject.getString("begindate")).append("' ");
  125. }
  126. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  127. // if(content.getString("type").equals("借用归还单")) {
  128. // where.append(" and t1.createdate <='" + whereObject.getString("enddate")).append("' ");
  129. // }else if(content.getString("type").equals("退货单")) {
  130. // where.append(" and t1.checkdate <='" + whereObject.getString("enddate")).append("' ");
  131. // }
  132. where.append(" and t1.billdate <='" + whereObject.getString("enddate")).append(" 23:59:59'");
  133. }
  134. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  135. where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
  136. }
  137. }
  138. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendrepair", "*");
  139. querySQL.setTableAlias("t1");
  140. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid","enterprisename");
  141. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t3", "t1.sys_enterpriseid = t3.sys_enterpriseid AND t1.siteid = t3.siteid","agentnum");
  142. querySQL.addJoinTable(JOINTYPE.left, "sa_sendrepair_detail", "t4", "t1.sa_sendrepairid = t4.sa_sendrepairid AND t1.siteid = t4.siteid","newspec","newitemno","newitemname",
  143. "newitemid","newsku","agentcost","practicalamount","instockdate","amount","logisticscost","logistics","idearemarks","disposition","demand","reason","duty",
  144. "stockdate","enddate","phonenumber","name","qty","itemid","sku");
  145. querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t5", "t5.itemid = t4.itemid AND t5.siteid = t4.siteid","itemname","itemno","spec","model");
  146. querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t6", "t5.unitid = t6.unitid AND t5.siteid = t6.siteid","unitname");
  147. querySQL.addQueryFields("remarksdetail","t4.remarks");
  148. querySQL.setSiteid(siteid);
  149. querySQL.setWhere(where.toString());
  150. querySQL.setPage(pageSize, pageNumber);
  151. Rows rows = querySQL.query();
  152. QuerySQL querySumSQL = SQLFactory.createQuerySQL(this, "sa_sendrepair_pj", "sa_sendrepairid");
  153. querySumSQL.setTableAlias("t1");
  154. querySumSQL.setSiteid(siteid);
  155. querySumSQL.addQueryFields("amount", "sum(amount)");
  156. querySumSQL.setWhere("t1.sa_sendrepairid",rows.toArrayList("sa_sendrepairid", new ArrayList<Long>()));
  157. querySumSQL.addGroupBy("sa_sendrepairid");
  158. RowsMap querySumRowsMap =querySumSQL.query().toRowsMap("sa_sendrepairid");
  159. for (Row row :rows){
  160. if(querySumRowsMap.containsKey(row.getString("sa_sendrepairid"))){
  161. row.put("ysamount",querySumRowsMap.get(row.getString("sa_sendrepairid")).get(0).getBigDecimal("amount"));
  162. }
  163. }
  164. return getSucReturnObject().setData(rows).toString();
  165. }
  166. @API(title = "删除", apiversion = R.ID2025070414210803.v1.class)
  167. @CACHEING_CLEAN(apiClass = {sendrepair.class})
  168. public String delete() throws YosException {
  169. JSONArray sa_sendrepairids = content.getJSONArray("sa_sendrepairids");
  170. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_sendrepairids.size());
  171. for (Object o : sa_sendrepairids) {
  172. long sa_sendrepairid = Long.parseLong(o.toString());
  173. Rows RowsStatus = dbConnect
  174. .runSqlQuery("select sa_sendrepairid,status,sourceid from sa_sendrepair where siteid='" + siteid
  175. + "' and sa_sendrepairid='" + sa_sendrepairid + "'");
  176. if (RowsStatus.isNotEmpty()) {
  177. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  178. batchDeleteErr.addErr(sa_sendrepairid, "非新建状态的送修单无法删除");
  179. continue;
  180. }
  181. }
  182. dbConnect.runSqlUpdate("delete from sa_sendrepair where siteid='" + siteid + "' and sa_sendrepairid="
  183. + sa_sendrepairid);
  184. dbConnect.runSqlUpdate("delete from sa_sendrepair_detail where siteid='" + siteid + "' and sa_sendrepairid="
  185. + sa_sendrepairid);
  186. dbConnect.runSqlUpdate("delete from sa_sendrepair_pj where siteid='" + siteid + "' and sa_sendrepairid="
  187. + sa_sendrepairid);
  188. dbConnect.runSqlUpdate("update st_stockbill set isrepair=0 where siteid='" + siteid + "' and st_stockbillid="
  189. + RowsStatus.get(0).getLong("sourceid"));
  190. dbConnect.runSqlUpdate("update st_stockbill_items set isrepair=0 where siteid='" + siteid + "' and st_stockbillid="
  191. + sa_sendrepairid);
  192. }
  193. return batchDeleteErr.getReturnObject().toString();
  194. }
  195. @API(title = "确认", apiversion = R.ID2025102409585903.v1.class)
  196. public String confirm() throws YosException {
  197. Long sa_sendrepairid = content.getLong("sa_sendrepairid");
  198. boolean isconfirm = content.getBooleanValue("isconfirm");
  199. Rows rows = dbConnect.runSqlQuery("select t1.billno,t1.status,t2.reason,t2.disposition from sa_sendrepair t1 inner join sa_sendrepair_detail t2 on t1.sa_sendrepairid=t2.sa_sendrepairid where t1.sa_sendrepairid ='"
  200. + sa_sendrepairid + "' and t1.siteid='" + siteid + "'");
  201. for (Row row : rows) {
  202. if (isconfirm) {
  203. if (!row.getString("status").equals("新建")) {
  204. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非新建状态,无法确认")
  205. .toString();
  206. }
  207. if (StringUtils.isBlank(row.getString("reason")) || StringUtils.isBlank(row.getString("disposition")) ) {
  208. return getErrReturnObject().setErrMsg("原因分析,处理意见必填")
  209. .toString();
  210. }
  211. } else {
  212. if (!row.getString("status").equals("确认")) {
  213. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非确认状态,无法反确认")
  214. .toString();
  215. }
  216. }
  217. }
  218. ArrayList<String> sqlList = new ArrayList<>();
  219. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair");
  220. updateSQL.setUniqueid(sa_sendrepairid);
  221. updateSQL.setSiteid(siteid);
  222. if (isconfirm) {
  223. updateSQL.setValue("status","确认");
  224. updateSQL.setValue("confirmby",username);
  225. updateSQL.setDateValue("confirmdate");
  226. sqlList.add(
  227. DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "确认", "送修单确认成功").getSQL());
  228. } else {
  229. updateSQL.setValue("status","新建");
  230. updateSQL.setValue("confirmby","");
  231. updateSQL.setValue("confirmdate","null");
  232. sqlList.add(
  233. DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "反确认", "送修单反确认成功").getSQL());
  234. }
  235. sqlList.add(updateSQL.getSQL());
  236. dbConnect.runSqlUpdate(sqlList);
  237. return getSucReturnObject().toString();
  238. }
  239. @API(title = "进仓", apiversion = R.ID2025102413280503.v1.class)
  240. public String instock() throws YosException {
  241. Long sa_sendrepairid = content.getLong("sa_sendrepairid");
  242. boolean isinstock = content.getBooleanValue("isinstock");
  243. Rows rows = dbConnect.runSqlQuery("select t1.sa_sendrepairid,t1.sys_enterpriseid,t1.remarks,t1.billno,t1.status,t2.qty,t2.sa_sendrepair_detailid,t2.reason,t2.disposition,t2.newitemno,t2.newsku,t2.newitemid,t2.sku,t2.name,t2.phonenumber,t2.address,t3.itemno,t2.itemid,t3.itemname,t3.model,t4.model newmodel,t4.skucontrol from sa_sendrepair t1 " +
  244. "inner join sa_sendrepair_detail t2 on t1.sa_sendrepairid=t2.sa_sendrepairid " +
  245. "left join plm_item t3 on t3.itemid=t2.itemid " +
  246. "left join plm_item t4 on t4.itemid=t2.newitemid " +
  247. " where t1.sa_sendrepairid ='"
  248. + sa_sendrepairid + "' and t1.siteid='" + siteid + "'");
  249. if(rows.isEmpty()){
  250. return getErrReturnObject().setErrMsg("送修单不存在")
  251. .toString();
  252. }
  253. Row row =rows.get(0);
  254. if (isinstock) {
  255. if (!row.getString("status").equals("确认")) {
  256. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非确认状态,无法进仓")
  257. .toString();
  258. }
  259. if (row.getString("disposition").equalsIgnoreCase(
  260. "翻新")) {
  261. if (row.getString("newitemno").equalsIgnoreCase(
  262. "")
  263. || row.getString("newsku")
  264. .equalsIgnoreCase("")) {
  265. return getErrReturnObject().setErrMsg("处理意见为翻新时应填写新的品号与新的序列号").toString();
  266. }
  267. if (row.getString("newitemid").equals(
  268. row.getString("itemid"))
  269. && row.getString("newsku")
  270. .equals(row
  271. .getString("sku"))) {
  272. return getErrReturnObject().setErrMsg("翻新前后序列号和品号不能相同").toString();
  273. }
  274. }
  275. if (row.getString("disposition").equals("待修")) {
  276. return getErrReturnObject().setErrMsg("待修不可进仓")
  277. .toString();
  278. }
  279. } else {
  280. if (!row.getString("status").equals("进仓")) {
  281. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非进仓状态,无法反进仓")
  282. .toString();
  283. }
  284. Rows stockbillRows = dbConnect.runSqlQuery("select type,typemx from st_stockbill where sourceid="+sa_sendrepairid+" and sourceobject='sa_sendrepair' and status='审核'");
  285. RowsMap stockbillRowsMap =stockbillRows.toRowsMap("type");
  286. if (stockbillRowsMap.containsKey("返修出库")) {
  287. return getErrReturnObject().setErrMsg("已生成的出库单已审核不可反进仓").toString();
  288. }
  289. if (stockbillRowsMap.containsKey("其他入库")) {
  290. for(Row stockbillRow :stockbillRowsMap.get("其他入库")){
  291. if(stockbillRow.getString("typemx").equals("正品入库")){
  292. return getErrReturnObject().setErrMsg("已生成的正品入库单已审核不可反进仓").toString();
  293. }
  294. }
  295. }
  296. }
  297. ArrayList<String> sqlList = new ArrayList<>();
  298. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair");
  299. updateSQL.setUniqueid(sa_sendrepairid);
  300. updateSQL.setSiteid(siteid);
  301. Rows dispositionRows =dbConnect.runSqlQuery("select * from sa_aftersalesmag_disposition where disposition='"+row.getString("disposition")+"'");
  302. Rows stockRows =dbConnect.runSqlQuery("select * from st_stock");
  303. RowsMap stockRowsMap = stockRows.toRowsMap("stockno");
  304. if(dispositionRows.isEmpty()){
  305. return getErrReturnObject().setErrMsg("返修处理意见不存在")
  306. .toString();
  307. }
  308. if (isinstock) {
  309. updateSQL.setValue("status","进仓");
  310. updateSQL.setValue("instockby",username);
  311. updateSQL.setDateValue("instockdate");
  312. sqlList.add(
  313. DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "进仓", "送修单进仓成功").getSQL());
  314. } else {
  315. updateSQL.setValue("status","确认");
  316. updateSQL.setValue("instockby","");
  317. updateSQL.setValue("instockdate","null");
  318. sqlList.add(
  319. DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "反进仓", "送修单反进仓成功").getSQL());
  320. }
  321. if(row.getString("disposition").equals("返修") || row.getString("disposition").equals("翻新")){
  322. if(isinstock){
  323. if(StringUtils.isBlank(row.getString("newitemno")) && StringUtils.isBlank(row.getString("newsku"))){
  324. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  325. long st_stockbillid = createTableID("st_stockbill");
  326. insertSQL.setUniqueid(st_stockbillid);
  327. insertSQL.setSiteid(siteid);
  328. insertSQL.setValue("billno", createBillCode("stockbilla"));
  329. insertSQL.setValue("type", "返修出库");
  330. insertSQL.setValue("typemx", "");
  331. insertSQL.setValue("sys_enterpriseid",row.getLong("sys_enterpriseid"));
  332. insertSQL.setValue("rb", 1);
  333. insertSQL.setValue("sourceobject", "sa_sendrepair");
  334. insertSQL.setValue("sourceid", sa_sendrepairid);
  335. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  336. insertSQL.setValue("remarks", row.getString("remarks"));
  337. insertSQL.setValue("status", "新建");
  338. insertSQL.setValue("createby", username);
  339. insertSQL.setDateValue("createdate");
  340. insertSQL.setDateValue("billdate");
  341. sqlList.add(insertSQL.getSQL());
  342. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  343. long st_stockbill_itemsid = createTableID("st_stockbill_items");
  344. insertSQL.setUniqueid(st_stockbill_itemsid);
  345. insertSQL.setSiteid(siteid);
  346. insertSQL.setValue("rowno", 1);
  347. insertSQL.setValue("sa_dispatch_itemsid", 0);
  348. insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
  349. insertSQL.setValue("sourceid", row.getLong("sa_sendrepair_detailid"));
  350. insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  351. insertSQL.setValue("itemid", row.getLong("itemid"));
  352. insertSQL.setValue("itemno", row.getString("itemno"));
  353. insertSQL.setValue("itemname", row.getString("itemname"));
  354. insertSQL.setValue("model", row.getString("model"));
  355. insertSQL.setValue("qty", row.getBigDecimal("qty"));
  356. insertSQL.setValue("st_stockbillid", st_stockbillid);
  357. sqlList.add(insertSQL.getSQL());
  358. if(StringUtils.isNotBlank(row.getString("sku"))){
  359. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  360. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  361. insertSQL.setUniqueid(st_stockbill_items_skuid);
  362. insertSQL.setSiteid(siteid);
  363. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  364. insertSQL.setValue("itemid", row.getLong("itemid"));
  365. insertSQL.setValue("sku", row.getString("sku"));
  366. insertSQL.setValue("st_stockbillid", st_stockbillid);
  367. insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
  368. sqlList.add(insertSQL.getSQL());
  369. }
  370. }else if(!row.getString("newsku").equals(row.getString("sku"))){
  371. sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
  372. sqlList.addAll(updatefnewmachinecode(isinstock,row,stockRowsMap));
  373. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  374. long st_stockbillid = createTableID("st_stockbill");
  375. insertSQL.setUniqueid(st_stockbillid);
  376. insertSQL.setSiteid(siteid);
  377. insertSQL.setValue("billno", createBillCode("stockbilla"));
  378. insertSQL.setValue("type", "返修出库");
  379. insertSQL.setValue("typemx", "");
  380. insertSQL.setValue("sys_enterpriseid",row.getLong("sys_enterpriseid"));
  381. insertSQL.setValue("rb", 1);
  382. insertSQL.setValue("sourceobject", "sa_sendrepair");
  383. insertSQL.setValue("sourceid", sa_sendrepairid);
  384. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  385. insertSQL.setValue("remarks", row.getString("remarks"));
  386. insertSQL.setValue("status", "新建");
  387. insertSQL.setValue("createby", username);
  388. insertSQL.setDateValue("createdate");
  389. insertSQL.setDateValue("billdate");
  390. sqlList.add(insertSQL.getSQL());
  391. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  392. long st_stockbill_itemsid = createTableID("st_stockbill_items");
  393. insertSQL.setUniqueid(st_stockbill_itemsid);
  394. insertSQL.setSiteid(siteid);
  395. insertSQL.setValue("rowno", 1);
  396. insertSQL.setValue("sa_dispatch_itemsid", 0);
  397. insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
  398. insertSQL.setValue("sourceid", row.getLong("sa_sendrepair_detailid"));
  399. insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  400. insertSQL.setValue("itemid", row.getLong("newitemid"));
  401. insertSQL.setValue("itemno", row.getString("newitemno"));
  402. insertSQL.setValue("itemname", row.getString("newitemname"));
  403. insertSQL.setValue("model", row.getString("newmodel"));
  404. insertSQL.setValue("qty", row.getBigDecimal("qty"));
  405. insertSQL.setValue("st_stockbillid", st_stockbillid);
  406. sqlList.add(insertSQL.getSQL());
  407. if(StringUtils.isNotBlank(row.getString("newsku"))){
  408. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  409. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  410. insertSQL.setUniqueid(st_stockbill_items_skuid);
  411. insertSQL.setSiteid(siteid);
  412. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  413. insertSQL.setValue("itemid", row.getLong("newitemid"));
  414. insertSQL.setValue("sku", row.getString("newsku"));
  415. insertSQL.setValue("st_stockbillid", st_stockbillid);
  416. insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
  417. sqlList.add(insertSQL.getSQL());
  418. }
  419. }else if(!row.getString("itemid").equals(row.getString("newitemid"))){
  420. sqlList.addAll(updatefitemno(isinstock,row));
  421. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  422. long st_stockbillid = createTableID("st_stockbill");
  423. insertSQL.setUniqueid(st_stockbillid);
  424. insertSQL.setSiteid(siteid);
  425. insertSQL.setValue("billno", createBillCode("stockbilla"));
  426. insertSQL.setValue("type", "返修出库");
  427. insertSQL.setValue("typemx", "");
  428. insertSQL.setValue("sys_enterpriseid",row.getLong("sys_enterpriseid"));
  429. insertSQL.setValue("rb", 1);
  430. insertSQL.setValue("sourceobject", "sa_sendrepair");
  431. insertSQL.setValue("sourceid", sa_sendrepairid);
  432. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  433. insertSQL.setValue("remarks", row.getString("remarks"));
  434. insertSQL.setValue("status", "新建");
  435. insertSQL.setValue("createby", username);
  436. insertSQL.setDateValue("createdate");
  437. insertSQL.setDateValue("billdate");
  438. sqlList.add(insertSQL.getSQL());
  439. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  440. long st_stockbill_itemsid = createTableID("st_stockbill_items");
  441. insertSQL.setUniqueid(st_stockbill_itemsid);
  442. insertSQL.setSiteid(siteid);
  443. insertSQL.setValue("rowno", 1);
  444. insertSQL.setValue("sa_dispatch_itemsid", 0);
  445. insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
  446. insertSQL.setValue("sourceid", row.getLong("sa_sendrepair_detailid"));
  447. insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  448. insertSQL.setValue("itemid", row.getLong("newitemid"));
  449. insertSQL.setValue("itemno", row.getString("newitemno"));
  450. insertSQL.setValue("itemname", row.getString("newitemname"));
  451. insertSQL.setValue("model", row.getString("newmodel"));
  452. insertSQL.setValue("qty", row.getBigDecimal("qty"));
  453. insertSQL.setValue("st_stockbillid", st_stockbillid);
  454. sqlList.add(insertSQL.getSQL());
  455. if(StringUtils.isNotBlank(row.getString("sku"))){
  456. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  457. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  458. insertSQL.setUniqueid(st_stockbill_items_skuid);
  459. insertSQL.setSiteid(siteid);
  460. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  461. insertSQL.setValue("itemid", row.getLong("newitemid"));
  462. insertSQL.setValue("sku", row.getString("sku"));
  463. insertSQL.setValue("st_stockbillid", st_stockbillid);
  464. insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
  465. sqlList.add(insertSQL.getSQL());
  466. }
  467. }
  468. }else{
  469. if(StringUtils.isBlank(row.getString("newitemno")) && StringUtils.isBlank(row.getString("newsku"))){
  470. } else if(!row.getString("newsku").equals(row.getString("sku"))){
  471. sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
  472. sqlList.addAll(updatefnewmachinecode(isinstock,row,stockRowsMap));
  473. } else if(!row.getString("itemid").equals(row.getString("newitemid"))){
  474. sqlList.addAll(updatefitemno(isinstock,row));
  475. }
  476. }
  477. }
  478. // 是否进成品仓
  479. if(dispositionRows.get(0).getBoolean("inishedstock")){
  480. if (isinstock) {
  481. sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
  482. sqlList.addAll(infinishedstock(isinstock,row));
  483. } else {
  484. sqlList.addAll(infinishedstock(isinstock,row));
  485. sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
  486. }
  487. }
  488. // 是否进报废仓
  489. if(dispositionRows.get(0).getBoolean("scrapstock")){
  490. if (isinstock) {
  491. sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
  492. sqlList.addAll(inscrapstock(isinstock,row,stockRowsMap));
  493. } else {
  494. sqlList.addAll(inscrapstock(isinstock,row,stockRowsMap));
  495. sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
  496. }
  497. }
  498. if(!isinstock){
  499. sqlList.add("delete from st_stockbill_items where st_stockbillid in (select st_stockbillid from st_stockbill where sourceobject='sa_sendrepair' and sourceid="+sa_sendrepairid+")");
  500. sqlList.add("delete from st_stockbill_items_sku where st_stockbillid in (select st_stockbillid from st_stockbill where sourceobject='sa_sendrepair' and sourceid="+sa_sendrepairid+")");
  501. sqlList.add("delete from st_stockbill where sourceobject='sa_sendrepair' and sourceid="+sa_sendrepairid);
  502. }
  503. sqlList.add(updateSQL.getSQL());
  504. System.err.println(sqlList.toString());
  505. dbConnect.runSqlUpdate(sqlList);
  506. return getSucReturnObject().toString();
  507. }
  508. @API(title = "审核", apiversion = R.ID2025102509532403.v1.class)
  509. public String check() throws YosException {
  510. ArrayList<String> sqlList = new ArrayList<>();
  511. Long sa_sendrepairid = content.getLong("sa_sendrepairid");
  512. boolean ischeck = content.getBooleanValue("ischeck");
  513. long sa_accountclassid=0;
  514. Rows accountclassrows = dbConnect.runSqlQuery("select * from sa_accountclass where accountno='01'");
  515. if(accountclassrows.isNotEmpty()){
  516. sa_accountclassid=accountclassrows.get(0).getLong("sa_accountclassid");
  517. }
  518. Rows rows = dbConnect.runSqlQuery("select t1.sys_enterpriseid,t1.remarks,t1.billno,t1.status,t2.qty,t2.sa_sendrepair_detailid,t2.amount,t2.agentcost,t2.disposition from sa_sendrepair t1 " +
  519. "inner join sa_sendrepair_detail t2 on t1.sa_sendrepairid=t2.sa_sendrepairid" +
  520. " where t1.sa_sendrepairid ='"
  521. + sa_sendrepairid + "' and t1.siteid='" + siteid + "'");
  522. if(rows.isEmpty()){
  523. return getErrReturnObject().setErrMsg("送修单不存在")
  524. .toString();
  525. }
  526. Row row =rows.get(0);
  527. Rows dispositionRows =dbConnect.runSqlQuery("select * from sa_aftersalesmag_disposition where disposition='"+row.getString("disposition")+"'");
  528. if(dispositionRows.isEmpty()){
  529. return getErrReturnObject().setErrMsg("返修处理意见不存在")
  530. .toString();
  531. }
  532. if (ischeck) {
  533. if (!row.getString("status").equals("进仓")) {
  534. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非进仓状态,无法审核")
  535. .toString();
  536. }
  537. } else {
  538. if (!dispositionRows.get(0).getBoolean("isrefund")) {
  539. if (!row.getString("status").equals("审核")) {
  540. return getErrReturnObject().setErrMsg("非审核状态下不可反审核").toString();
  541. }
  542. } else {
  543. if (!row.getString("status").equals("退款确认")) {
  544. return getErrReturnObject().setErrMsg("非退款确认状态下不可反审核").toString();
  545. }
  546. }
  547. }
  548. // 是否维修
  549. if (dispositionRows.get(0).getBoolean("ismaintain")) {
  550. /******** 账户余额扣减 ********/
  551. BigDecimal totalamount = rows.sum("agentcost");// 经销商维修支付费用总额
  552. // 如果经销商维修费用大于0
  553. if (totalamount.compareTo(BigDecimal.ZERO)>0) {
  554. if (ischeck) {
  555. CashbillEntity cashbillEntity = new CashbillEntity();
  556. cashbillEntity.setAmount(totalamount);
  557. cashbillEntity.setDiscountamountamount(BigDecimal.ZERO);
  558. cashbillEntity.setOwnerid(sa_sendrepairid);
  559. cashbillEntity.setOwnertable("sa_sendrepair");
  560. cashbillEntity.setRemarks("该单由送修单" + row.getString("billno") + "审核时自动生成");
  561. cashbillEntity.setSource("送修单审核");
  562. cashbillEntity.setTypemx("维修费");
  563. JSONObject cashbillPay = Accountbalance.createCashbillPay(this, row.getLong("sys_enterpriseid"), sa_accountclassid, cashbillEntity, true);
  564. sqlList.addAll(cashbillPay.getJSONArray("sqlList").toJavaList(String.class));
  565. } else {
  566. CashbillEntity cashbillEntity = new CashbillEntity();
  567. cashbillEntity.setAmount(totalamount.negate());
  568. cashbillEntity.setDiscountamountamount(BigDecimal.ZERO);
  569. cashbillEntity.setOwnerid(sa_sendrepairid);
  570. cashbillEntity.setOwnertable("sa_sendrepair");
  571. cashbillEntity.setRemarks("该单由送修单" + row.getString("billno") + "反审核时自动生成");
  572. cashbillEntity.setSource("送修单反审核");
  573. cashbillEntity.setTypemx("维修费");
  574. JSONObject cashbillPay = Accountbalance.createCashbillPay(this, row.getLong("sys_enterpriseid"), sa_accountclassid, cashbillEntity, true);
  575. sqlList.addAll(cashbillPay.getJSONArray("sqlList").toJavaList(String.class));
  576. }
  577. }
  578. }
  579. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair");
  580. updateSQL.setUniqueid(sa_sendrepairid);
  581. updateSQL.setSiteid(siteid);
  582. if (ischeck) {
  583. if (!dispositionRows.get(0).getBoolean("isrefund")) {
  584. updateSQL.setValue("status","审核");
  585. }else{
  586. updateSQL.setValue("status","退款确认");
  587. }
  588. updateSQL.setValue("checkby",username);
  589. updateSQL.setDateValue("checkdate");
  590. sqlList.add(
  591. DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "审核", "送修单审核成功").getSQL());
  592. } else {
  593. updateSQL.setValue("status","进仓");
  594. updateSQL.setValue("checkby","");
  595. updateSQL.setValue("checkdate","null");
  596. sqlList.add(
  597. DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "反审核", "送修单反审核成功").getSQL());
  598. }
  599. sqlList.add(updateSQL.getSQL());
  600. dbConnect.runSqlUpdate(sqlList);
  601. return getSucReturnObject().toString();
  602. }
  603. /**
  604. * 翻新序列号不变 品号改变
  605. *
  606. */
  607. public ArrayList<String> updatefitemno(boolean istrue,Row sendrepairdetail) throws YosException {
  608. ArrayList<String> sqlList = new ArrayList<>();
  609. Rows skurows =dbConnect.runSqlQuery("select * from sa_itemsku where sku='"+sendrepairdetail.getString("sku")+"' and status!='报废'");
  610. if(skurows.isEmpty()){
  611. throw new YosException("序列号不存在或已作废");
  612. }
  613. long newitemid = sendrepairdetail.getLong("newitemid");
  614. String remarks = "由送修单号为" + sendrepairdetail.getString("billno") + "更改品号";
  615. if (skurows.size() == 1) {
  616. Row skurow =skurows.get(0);
  617. if (istrue) {
  618. if (newitemid==sendrepairdetail.getLong("itemid")) {
  619. throw new YosException( "调整品号不可与原品号相同");
  620. }
  621. if (newitemid==0) {
  622. throw new YosException( "调整品号不可为空");
  623. }
  624. if (!sendrepairdetail.getBoolean("skucontrol")) {
  625. throw new YosException("调整品号不是单品管理");
  626. }
  627. if (skurow.getLong("wmsuploadflag") == 2) {
  628. sqlList.add("update sa_itemsku set itemid="+newitemid+",changenotes='"+remarks+"',wmsuploadflag=1 where sa_itemskuid="+skurow.getLong("sa_itemskuid"));
  629. }else{
  630. sqlList.add("update sa_itemsku set itemid="+newitemid+",changenotes='"+remarks+"' where sa_itemskuid="+skurow.getLong("sa_itemskuid"));
  631. }
  632. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_itemsku_change");
  633. insertSQL.setValue("siteid", siteid);
  634. insertSQL.setValue("sa_itemsku_changeid", createTableID("sa_itemsku_change"));
  635. insertSQL.setValue("sa_itemskuid", skurow.getLong("sa_itemskuid"));
  636. insertSQL.setValue("sa_agentsid", skurow.getLong("sa_agentsid"));
  637. insertSQL.setValue("sa_agentsidnew", skurow.getLong("sa_agentsid"));
  638. insertSQL.setValue("itemid", skurow.getLong("itemid"));
  639. insertSQL.setValue("itemidnew", newitemid);
  640. insertSQL.setValue("stockid", skurow.getLong("stockid"));
  641. insertSQL.setValue("stockidnew", skurow.getLong("stockid"));
  642. insertSQL.setValue("changenotes", remarks);
  643. insertSQL.setDateValue("changedate");
  644. insertSQL.setValue("changeby", username);
  645. sqlList.add(insertSQL.getSQL());
  646. }
  647. if (!istrue) {
  648. sqlList.add("update sa_itemsku set itemid="+sendrepairdetail.getLong("itemid")+",changenotes='null' where sa_itemskuid="+skurow.getLong("sa_itemskuid"));
  649. sqlList.add("delete from sa_itemsku_change where changenotes like '%"+sendrepairdetail.getString("billno")+"%'");
  650. }
  651. }
  652. return sqlList;
  653. }
  654. /**
  655. * 翻新新序列号入库
  656. *
  657. */
  658. public ArrayList<String> updatefnewmachinecode(boolean istrue,Row sendrepairdetail,RowsMap stockRowsMap) throws YosException {
  659. ArrayList<String> sqlList = new ArrayList<>();
  660. Rows departmentRows =dbConnect.runSqlQuery("select * from sys_department");
  661. RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
  662. String sku = sendrepairdetail.getString("sku");
  663. String newsku = sendrepairdetail.getString("newsku");
  664. if (istrue) {
  665. if (!sku.equals(newsku)) {
  666. InsertSQL saItemsku = SQLFactory.createInsertSQL(this,"sa_itemsku");
  667. saItemsku.setValue("sku", newsku);
  668. saItemsku.setValue("itemid", sendrepairdetail.getLong("newitemid"));
  669. saItemsku.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  670. saItemsku.setValue("createby", username);
  671. saItemsku.setDateValue("createdate");
  672. saItemsku.setValue("changeby", username);
  673. saItemsku.setDateValue("changedate");
  674. saItemsku.setValue("changenotes", "");
  675. saItemsku.setValue("mono", "");
  676. saItemsku.setValue("sa_itemskuid", createTableID("sa_itemsku"));
  677. saItemsku.setSiteid(siteid);
  678. sqlList.add(saItemsku.getSQL());
  679. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  680. long st_stockbillid = createTableID("st_stockbill");
  681. insertSQL.setUniqueid(st_stockbillid);
  682. insertSQL.setSiteid(siteid);
  683. insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
  684. insertSQL.setValue("type", "其他入库");
  685. insertSQL.setValue("typemx", "翻新/返修入库");
  686. insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
  687. insertSQL.setValue("rb", 1);
  688. insertSQL.setValue("sourceobject", "sa_sendrepair");
  689. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
  690. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
  691. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  692. insertSQL.setValue("remarks", "送修单入库");
  693. insertSQL.setValue("status", "审核");
  694. insertSQL.setValue("createby", username);
  695. insertSQL.setDateValue("createdate");
  696. insertSQL.setValue("checkby", username);
  697. insertSQL.setDateValue("checkdate");
  698. insertSQL.setDateValue("billdate");
  699. sqlList.add(insertSQL.getSQL());
  700. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  701. long st_stockbill_itemsid = createTableID("st_stockbill_items");
  702. insertSQL.setUniqueid(st_stockbill_itemsid);
  703. insertSQL.setSiteid(siteid);
  704. insertSQL.setValue("rowno", 1);
  705. insertSQL.setValue("sa_dispatch_itemsid", 0);
  706. insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
  707. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
  708. insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  709. insertSQL.setValue("itemid", sendrepairdetail.getLong("newitemid"));
  710. insertSQL.setValue("itemno", sendrepairdetail.getString("newitemno"));
  711. insertSQL.setValue("itemname", sendrepairdetail.getString("newitemname"));
  712. insertSQL.setValue("model", sendrepairdetail.getString("newmodel"));
  713. insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
  714. insertSQL.setValue("st_stockbillid", st_stockbillid);
  715. sqlList.add(insertSQL.getSQL());
  716. if(StringUtils.isNotBlank(sendrepairdetail.getString("newsku"))){
  717. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  718. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  719. insertSQL.setUniqueid(st_stockbill_items_skuid);
  720. insertSQL.setSiteid(siteid);
  721. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  722. insertSQL.setValue("itemid", sendrepairdetail.getLong("newitemid"));
  723. insertSQL.setValue("sku", sendrepairdetail.getString("newsku"));
  724. insertSQL.setValue("st_stockbillid", st_stockbillid);
  725. insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
  726. sqlList.add(insertSQL.getSQL());
  727. }
  728. sqlList.addAll(sendrepairIcinvbal_new(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
  729. }
  730. }
  731. if (!istrue) {
  732. sqlList.addAll(sendrepairIcinvbal_new(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
  733. //sqlList.add("delete from st_stockbill where type='其他入库' and sourceobject='sa_sendrepair' and sourceid="+sendrepairdetail.getLong("sendrepairid"));
  734. sqlList.add("delete from sa_itemsku where sku='"+sendrepairdetail.getString("newsku")+"'");
  735. }
  736. return sqlList;
  737. }
  738. /**
  739. * 翻新 老序列号出库
  740. *
  741. */
  742. public ArrayList<String> updatefmachinecode(boolean istrue,Row sendrepairdetail,RowsMap stockRowsMap) throws YosException {
  743. ArrayList<String> sqlList = new ArrayList<>();
  744. Rows departmentRows =dbConnect.runSqlQuery("select * from sys_department");
  745. RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
  746. if (istrue) {
  747. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  748. long st_stockbillid = createTableID("st_stockbill");
  749. insertSQL.setUniqueid(st_stockbillid);
  750. insertSQL.setSiteid(siteid);
  751. insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
  752. insertSQL.setValue("type", "其他出库");
  753. if (sendrepairdetail.getString("disposition").equalsIgnoreCase("返修")) {
  754. insertSQL.setValue("typemx", "返修出库");
  755. } else if (sendrepairdetail.getString("disposition").equalsIgnoreCase("翻新")) {
  756. insertSQL.setValue("typemx", "翻新出库");
  757. } else if (sendrepairdetail.getString("disposition").contains("报废")) {
  758. insertSQL.setValue("typemx", "报废出库");
  759. } else if (sendrepairdetail.getString("disposition").equalsIgnoreCase("退钱做正品")) {
  760. insertSQL.setValue("typemx", "退钱做正品出库");
  761. } else if (sendrepairdetail.getString("disposition").equalsIgnoreCase("退钱做试验机")) {
  762. insertSQL.setValue("typemx", "退钱做试验机出库");
  763. }
  764. insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
  765. insertSQL.setValue("rb", 1);
  766. insertSQL.setValue("sourceobject", "sa_sendrepair");
  767. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
  768. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
  769. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  770. insertSQL.setValue("remarks", "送修单出库");
  771. insertSQL.setValue("status", "审核");
  772. insertSQL.setValue("createby", username);
  773. insertSQL.setDateValue("createdate");
  774. insertSQL.setDateValue("billdate");
  775. insertSQL.setValue("checkby", username);
  776. insertSQL.setDateValue("checkdate");
  777. sqlList.add(insertSQL.getSQL());
  778. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  779. long st_stockbill_itemsid = createTableID("st_stockbill_items");
  780. insertSQL.setUniqueid(st_stockbill_itemsid);
  781. insertSQL.setSiteid(siteid);
  782. insertSQL.setValue("rowno", 1);
  783. insertSQL.setValue("sa_dispatch_itemsid", 0);
  784. insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
  785. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
  786. insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  787. insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
  788. insertSQL.setValue("itemno", sendrepairdetail.getString("itemno"));
  789. insertSQL.setValue("itemname", sendrepairdetail.getString("itemname"));
  790. insertSQL.setValue("model", sendrepairdetail.getString("model"));
  791. insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
  792. insertSQL.setValue("st_stockbillid", st_stockbillid);
  793. sqlList.add(insertSQL.getSQL());
  794. if(StringUtils.isNotBlank(sendrepairdetail.getString("sku"))){
  795. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  796. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  797. insertSQL.setUniqueid(st_stockbill_items_skuid);
  798. insertSQL.setSiteid(siteid);
  799. insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
  800. insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
  801. insertSQL.setValue("sku", sendrepairdetail.getString("sku"));
  802. insertSQL.setValue("st_stockbillid", st_stockbillid);
  803. insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
  804. sqlList.add(insertSQL.getSQL());
  805. }
  806. sqlList.addAll(sendrepairIcinvbal(isinstock("其他出库","1",istrue),sendrepairdetail, stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
  807. sqlList.add("update sa_itemsku set stockid=0 where sku='"+sendrepairdetail.getString("sku")+"'");
  808. if(sendrepairdetail.getString("disposition").equalsIgnoreCase("翻新") || sendrepairdetail.getString("disposition").equalsIgnoreCase("返修")){
  809. sqlList.add("update sa_itemsku set status='报废' where sku='"+sendrepairdetail.getString("sku")+"'");
  810. }
  811. }
  812. if (!istrue) {
  813. sqlList.addAll(sendrepairIcinvbal(isinstock("其他出库","1",istrue),sendrepairdetail, stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
  814. sqlList.add("update sa_itemsku set status='在库',stockid='"+(stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0)+"' where sku='"+sendrepairdetail.getString("sku")+"'");
  815. }
  816. return sqlList;
  817. }
  818. /**
  819. * 正品入库
  820. *
  821. */
  822. public ArrayList<String> infinishedstock(boolean istrue,Row sendrepairdetail) throws YosException {
  823. ArrayList<String> sqlList = new ArrayList<>();
  824. Rows departmentRows =dbConnect.runSqlQuery("select * from sys_department");
  825. RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
  826. if (istrue) {
  827. /*************** 售后开始 ****************/
  828. long stockid = 0;
  829. long itemid = sendrepairdetail.getLong("itemid");
  830. Rows itemrows = dbConnect.runSqlQuery("select t2.stockid from plm_item t1 left join st_stock t2 on t1.stockno=t2.stockno where t1.itemid="+itemid);
  831. if (itemrows.isNotEmpty()) {
  832. stockid = itemrows.get(0).getLong("stockid");
  833. if (stockid==0) {
  834. throw new YosException("货品档案中该商品没有默认仓库,请先补齐信息");
  835. }
  836. } else {
  837. throw new YosException("系统货品档案中不存在该品号");
  838. }
  839. /*************** 售后结束 ****************/
  840. /*************** 电商出库开始 ****************/
  841. String name = sendrepairdetail.getString("name");
  842. String phonenumber = sendrepairdetail.getString("phonenumber");
  843. String address = sendrepairdetail.getString("address");
  844. String fnotes = "";
  845. if (!name.equals("")) {
  846. fnotes = "姓名:" + name + ",电话:" + phonenumber + ".地址:" + address;
  847. }
  848. /*************** 电商出库结束 ****************/
  849. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  850. long st_stockbillid = createTableID("st_stockbill");
  851. insertSQL.setUniqueid(st_stockbillid);
  852. insertSQL.setSiteid(siteid);
  853. insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
  854. insertSQL.setValue("type", "其他入库");
  855. insertSQL.setValue("typemx", "正品入库");
  856. insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
  857. insertSQL.setValue("rb", 1);
  858. insertSQL.setValue("sourceobject", "sa_sendrepair");
  859. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
  860. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
  861. insertSQL.setValue("stockid", stockid);
  862. insertSQL.setValue("remarks", fnotes);
  863. insertSQL.setValue("status", "新建");
  864. insertSQL.setValue("createby", username);
  865. insertSQL.setDateValue("createdate");
  866. insertSQL.setDateValue("billdate");
  867. sqlList.add(insertSQL.getSQL());
  868. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  869. long st_stockbill_itemsid = createTableID("st_stockbill_items");
  870. insertSQL.setUniqueid(st_stockbill_itemsid);
  871. insertSQL.setSiteid(siteid);
  872. insertSQL.setValue("rowno", 1);
  873. insertSQL.setValue("sa_dispatch_itemsid", 0);
  874. insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
  875. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
  876. insertSQL.setValue("stockid",stockid);
  877. insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
  878. insertSQL.setValue("itemno", sendrepairdetail.getString("itemno"));
  879. insertSQL.setValue("itemname", sendrepairdetail.getString("itemname"));
  880. insertSQL.setValue("model", sendrepairdetail.getString("model"));
  881. insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
  882. insertSQL.setValue("st_stockbillid", st_stockbillid);
  883. sqlList.add(insertSQL.getSQL());
  884. if(StringUtils.isNotBlank(sendrepairdetail.getString("sku"))){
  885. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  886. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  887. insertSQL.setUniqueid(st_stockbill_items_skuid);
  888. insertSQL.setSiteid(siteid);
  889. insertSQL.setValue("stockid", stockid);
  890. insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
  891. insertSQL.setValue("sku", sendrepairdetail.getString("sku"));
  892. insertSQL.setValue("st_stockbillid", st_stockbillid);
  893. insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
  894. sqlList.add(insertSQL.getSQL());
  895. }
  896. }
  897. if (!istrue) {
  898. sqlList.add("update sa_itemsku set stockid=0 where sku='"+sendrepairdetail.getString("sku")+"'");
  899. }
  900. return sqlList;
  901. }
  902. /**
  903. * 报废入库报废仓
  904. *
  905. */
  906. public ArrayList<String> inscrapstock(boolean istrue,Row sendrepairdetail,RowsMap stockRowsMap) throws YosException {
  907. ArrayList<String> sqlList = new ArrayList<>();
  908. Rows departmentRows =dbConnect.runSqlQuery("select * from sys_department");
  909. RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
  910. if (istrue) {
  911. String name = sendrepairdetail.getString("name");
  912. String phonenumber = sendrepairdetail.getString("phonenumber");
  913. String address = sendrepairdetail.getString("address");
  914. String fnotes = "";
  915. if (!name.equals("")) {
  916. fnotes = "姓名:" + name + ",电话:" + phonenumber + ".地址:" + address;
  917. }
  918. /*************** 电商出库结束 ****************/
  919. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
  920. long st_stockbillid = createTableID("st_stockbill");
  921. insertSQL.setUniqueid(st_stockbillid);
  922. insertSQL.setSiteid(siteid);
  923. insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
  924. insertSQL.setValue("type", "其他入库");
  925. insertSQL.setValue("typemx", "报废入库");
  926. insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
  927. insertSQL.setValue("rb", 1);
  928. insertSQL.setValue("sourceobject", "sa_sendrepair");
  929. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
  930. insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
  931. insertSQL.setValue("stockid", stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0);
  932. insertSQL.setValue("remarks", "送修单入库");
  933. insertSQL.setValue("status", "新建");
  934. insertSQL.setValue("createby", username);
  935. insertSQL.setDateValue("createdate");
  936. insertSQL.setDateValue("billdate");
  937. sqlList.add(insertSQL.getSQL());
  938. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
  939. long st_stockbill_itemsid = createTableID("st_stockbill_items");
  940. insertSQL.setUniqueid(st_stockbill_itemsid);
  941. insertSQL.setSiteid(siteid);
  942. insertSQL.setValue("rowno", 1);
  943. insertSQL.setValue("sa_dispatch_itemsid", 0);
  944. insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
  945. insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
  946. insertSQL.setValue("stockid",stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0);
  947. insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
  948. insertSQL.setValue("itemno", sendrepairdetail.getString("itemno"));
  949. insertSQL.setValue("itemname", sendrepairdetail.getString("itemname"));
  950. insertSQL.setValue("model", sendrepairdetail.getString("model"));
  951. insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
  952. insertSQL.setValue("st_stockbillid", st_stockbillid);
  953. sqlList.add(insertSQL.getSQL());
  954. if(StringUtils.isNotBlank(sendrepairdetail.getString("sku"))){
  955. insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
  956. long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
  957. insertSQL.setUniqueid(st_stockbill_items_skuid);
  958. insertSQL.setSiteid(siteid);
  959. insertSQL.setValue("stockid", stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0);
  960. insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
  961. insertSQL.setValue("sku", sendrepairdetail.getString("sku"));
  962. insertSQL.setValue("st_stockbillid", st_stockbillid);
  963. insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
  964. sqlList.add(insertSQL.getSQL());
  965. }
  966. sqlList.addAll(sendrepairIcinvbal(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0));
  967. sqlList.add("update sa_itemsku set stockid="+(stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0)+" where sku='"+sendrepairdetail.getString("sku")+"'");
  968. }
  969. if (!istrue) {
  970. sqlList.addAll(sendrepairIcinvbal(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0));
  971. sqlList.add("update sa_itemsku set stockid=0 where sku='"+sendrepairdetail.getString("sku")+"'");
  972. }
  973. return sqlList;
  974. }
  975. public ArrayList<String> sendrepairIcinvbal_new(boolean isinstock,Row sendrepairdetail,long stockid) throws YosException {// 云链
  976. ArrayList<String> sqlList =new ArrayList<>();
  977. long newitemid = sendrepairdetail.getLong("newitemid");
  978. String newitemno = sendrepairdetail.getString("newitemno");
  979. ArrayList<Long> itemList= new ArrayList<>();
  980. itemList.add(newitemid);
  981. RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal").setWhere("siteid", siteid).setWhere("itemid",itemList).query().toRowsMap("itemid");
  982. BigDecimal qty =isinstock ? sendrepairdetail.getBigDecimal("qty") : sendrepairdetail.getBigDecimal("qty").negate();
  983. if (!invbalsRowsMap.containsKey(String.valueOf(newitemid)) || !invbalsRowsMap.get(String.valueOf(newitemid)).toRowsMap("stockid").containsKey(String.valueOf(stockid))) {
  984. InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal");
  985. invbalInsert.setValue("siteid", siteid);
  986. invbalInsert.setValue("stockid", stockid);
  987. invbalInsert.setValue("itemid", newitemid);
  988. invbalInsert.setValue("qty", qty.doubleValue());
  989. sqlList.add(invbalInsert.getSQL());
  990. } else {
  991. UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal");
  992. invbalUpdate.addValue("qty",qty);
  993. invbalUpdate.setWhere("itemid", newitemid);
  994. invbalUpdate.setWhere("stockid", stockid);
  995. invbalUpdate.setWhere("siteid", siteid);
  996. sqlList.add(invbalUpdate.getSQL());
  997. }
  998. return sqlList;
  999. }
  1000. public ArrayList<String> sendrepairIcinvbal(boolean isinstock,Row sendrepairdetail,long stockid) throws YosException {// 云链
  1001. ArrayList<String> sqlList =new ArrayList<>();
  1002. long itemid = sendrepairdetail.getLong("itemid");
  1003. ArrayList<Long> itemList= new ArrayList<>();
  1004. itemList.add(itemid);
  1005. RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal").setWhere("siteid", siteid).setWhere("itemid",itemList).query().toRowsMap("itemid");
  1006. BigDecimal qty =isinstock ? sendrepairdetail.getBigDecimal("qty") : sendrepairdetail.getBigDecimal("qty").negate();
  1007. if (!invbalsRowsMap.containsKey(String.valueOf(itemid)) || !invbalsRowsMap.get(String.valueOf(itemid)).toRowsMap("stockid").containsKey(String.valueOf(stockid))) {
  1008. InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal");
  1009. invbalInsert.setValue("siteid", siteid);
  1010. invbalInsert.setValue("stockid", stockid);
  1011. invbalInsert.setValue("itemid", itemid);
  1012. invbalInsert.setValue("qty", qty.doubleValue());
  1013. sqlList.add(invbalInsert.getSQL());
  1014. } else {
  1015. UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal");
  1016. invbalUpdate.addValue("qty", qty);
  1017. invbalUpdate.setWhere("itemid", itemid);
  1018. invbalUpdate.setWhere("stockid", stockid);
  1019. invbalUpdate.setWhere("siteid", siteid);
  1020. sqlList.add(invbalUpdate.getSQL());
  1021. }
  1022. return sqlList;
  1023. }
  1024. public boolean isinstock(String type, String rb, boolean fischeck) {
  1025. if (type.equals("其他出库") || type.equals("销售出库")
  1026. || type.equals("生产领料出库") || type.equals("委外领料出库")
  1027. || type.equals("返修出库")) {
  1028. if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
  1029. return false;
  1030. } else {
  1031. return true;
  1032. }
  1033. } else if (type.equals("其他入库") || type.equals("外购入库")
  1034. || type.equals("生产入库") || type.equals("委外入库")
  1035. || type.equals("返修入库")) {
  1036. if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
  1037. return true;
  1038. } else {
  1039. return false;
  1040. }
  1041. }
  1042. return false;
  1043. }
  1044. }