| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package restcontroller.webmanage.sale.sendrepair;
- import beans.data.BatchDeleteErr;
- import beans.itemprice.ItemPrice;
- import com.alibaba.fastjson2.JSONArray;
- import com.alibaba.fastjson2.JSONObject;
- import common.Controller;
- import common.YosException;
- import common.annotation.API;
- import common.annotation.CACHEING;
- import common.annotation.CACHEING_CLEAN;
- import common.data.*;
- import restcontroller.R;
- import java.util.ArrayList;
- import java.util.HashMap;
- @API(title = "送修单配件")
- public class sendrepair_pj extends Controller {
- public sendrepair_pj(JSONObject content) throws YosException {
- super(content);
- }
- @API(title = "送修配件列表查询", apiversion = R.ID2025070414582703.v1.class)
- @CACHEING
- public String queryOrderItemgList() throws YosException {
- long sa_sendrepairid=content.getLong("sa_sendrepairid");
- Rows sendrepairrows =dbConnect.runSqlQuery("select sys_enterpriseid from sa_sendrepair where sa_sendrepairid="+sa_sendrepairid);
- if(sendrepairrows.isEmpty()){
- return getErrReturnObject().setErrMsg("送修单不存在").toString();
- }
- sys_enterpriseid=sendrepairrows.get(0).getLong("sys_enterpriseid");
- /*
- * 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t1.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item", "*");
- querySQL.setTableAlias("t1");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("isused=1 and status='审核' and ismodule=1");
- querySQL.setWhere("t1.itemid not in (select itemid from sa_sendrepair_pj where sa_sendrepairid='"+content.getLongValue("sa_sendrepairid")+"')");
- querySQL.setWhere(where.toString());
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- HashMap<Long, ItemPrice> itemPriceRowsMap = ItemPrice.getItemPrice(this, sys_enterpriseid,rows.toArrayList("itemid", new ArrayList<>()));
- for (Row row :rows){
- if (itemPriceRowsMap.containsKey(row.getLong("itemid"))) {
- row.put("price", itemPriceRowsMap.get(row.getLong("itemid")).getPrice());
- } else {
- row.put("price", 0);
- }
- }
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "送修单明细新增更新", apiversion = R.ID2025070414583703.v1.class)
- @CACHEING_CLEAN(apiClass = {sendrepair.class, sendrepair_pj.class})
- public String insertormodify_sendrepairpjs() throws YosException {
- Long sa_sendrepairid = content.getLong("sa_sendrepairid");
- JSONArray iteminfos = content.getJSONArray("iteminfos");
- ArrayList<String> sqlList = new ArrayList<>();
- Rows rowscount = dbConnect.runSqlQuery("select billno,status from sa_sendrepair where sa_sendrepairid=" + sa_sendrepairid);
- if (!rowscount.isEmpty()) {
- if (rowscount.get(0).getString("status").equals("审核") || rowscount.get(0).getString("status").equals("退款确认")) {
- return getErrReturnObject().setErrMsg("审核或退款确认状态的送修单无法新增修改").toString();
- }
- }
- int i = 0;
- long maxid = 0;
- long[] sa_sendrepair_pjid = createTableID("sa_sendrepair_pj", iteminfos.size());
- for (Object obj : iteminfos) {
- JSONObject iteminfo = (JSONObject) obj;
- if (iteminfo.getLong("sa_sendrepair_pjid") <= 0 || dbConnect
- .runSqlQuery("select sa_sendrepair_pjid from sa_sendrepair_pj where sa_sendrepair_pjid="
- + iteminfo.getLong("sa_sendrepair_pjid"))
- .isEmpty()) {
- InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_sendrepair_pj");
- insertSQL.setUniqueid(sa_sendrepair_pjid[i]);
- insertSQL.setSiteid(siteid);
- insertSQL.setValue("sa_sendrepairid", sa_sendrepairid);
- insertSQL.setValue("itemid", iteminfo.getStringValue("itemid"));
- insertSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
- insertSQL.setValue("price", iteminfo.getBigDecimal("price"));
- insertSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
- i++;
- sqlList.add(insertSQL.getSQL());
- } else {
- Rows rows = dbConnect.runSqlQuery(
- "SELECT status from sa_sendrepair WHERE sa_sendrepairid = "
- + sa_sendrepairid);
- if (rows.isNotEmpty()) {
- if (rows.get(0).getString("status").equals("新建")) {
- UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair_pj");
- updateSQL.setUniqueid(iteminfo.getLong("sa_sendrepair_pjid"));
- updateSQL.setSiteid(siteid);
- updateSQL.setValue("itemid", iteminfo.getString("itemid"));
- updateSQL.setValue("qty", iteminfo.getBigDecimal("qty"));
- updateSQL.setValue("price", iteminfo.getBigDecimal("price"));
- updateSQL.setValue("amount", iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
- sqlList.add(updateSQL.getSQL());
- } else {
- return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
- }
- } else {
- return getErrReturnObject().setErrMsg("该送修单不存在").toString();
- }
- }
- }
- dbConnect.runSqlUpdate(sqlList);
- return quersendrepairpjsList();
- }
- @API(title = "送修单配件列表", apiversion = R.ID2025070414584903.v1.class)
- @CACHEING
- public String quersendrepairpjsList() throws YosException {
- /*
- * 过滤条件设置
- */
- StringBuffer where = new StringBuffer(" 1=1 ");
- if (content.containsKey("where")) {
- JSONObject whereObject = content.getJSONObject("where");
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
- where.append(" and(");
- where.append("t2.itemname like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.model like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.spec like'%").append(whereObject.getString("condition")).append("%' ");
- where.append("or t2.itemno like'%").append(whereObject.getString("condition")).append("%' ");
- where.append(")");
- }
- }
- Long sa_sendrepairid = content.getLong("sa_sendrepairid");
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_sendrepair_pj", "*");
- querySQL.setTableAlias("t1");
- querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t2", "t1.itemid = t2.itemid AND t1.siteid = t2.siteid","itemname","itemno","spec","model");
- querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t3", "t2.unitid = t3.unitid AND t2.siteid = t3.siteid","unitname");
- querySQL.setSiteid(siteid);
- querySQL.setWhere("t1.sa_sendrepairid",sa_sendrepairid);
- querySQL.setWhere(where.toString());
- querySQL.setPage(pageSize, pageNumber);
- Rows rows = querySQL.query();
- return getSucReturnObject().setData(rows).toString();
- }
- @API(title = "删除明细", apiversion = R.ID2025070414590403.v1.class)
- @CACHEING_CLEAN(apiClass = {sendrepair.class, sendrepair_pj.class})
- public String deletemx() throws YosException {
- JSONArray sa_sendrepair_pjids = content.getJSONArray("sa_sendrepair_pjids");
- BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_sendrepair_pjids.size());
- long sa_sendrepairid = 0;
- for (Object o : sa_sendrepair_pjids) {
- long sa_sendrepair_pjid = Long.parseLong(o.toString());
- 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='"
- + siteid + "' and t1.sa_sendrepair_pjid='" + sa_sendrepair_pjid + "'");
- if (RowsStatus.isNotEmpty()) {
- sa_sendrepairid = RowsStatus.get(0).getLong("sa_sendrepairid");
- if (!RowsStatus.get(0).getString("status").equals("新建")) {
- batchDeleteErr.addErr(sa_sendrepair_pjid, "非新建状态的送修单明细无法删除");
- continue;
- }
- }
- ArrayList<String> list = new ArrayList<>();
- list.add("delete from sa_sendrepair_pj where siteid='" + siteid
- + "' and sa_sendrepair_pjid=" + sa_sendrepair_pjid);
- dbConnect.runSqlUpdate(list);
- }
- return batchDeleteErr.getReturnObject().toString();
- }
-
- }
|