|
|
@@ -0,0 +1,227 @@
|
|
|
+package restcontroller.prsx.trial;
|
|
|
+
|
|
|
+import beans.brand.Brand;
|
|
|
+import beans.itemclass.ItemClass;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.*;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+import static beans.order.Order.getOrderRows;
|
|
|
+
|
|
|
+public class trialitems extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public trialitems(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "查询可添加商品列表", apiversion = R.ID2025110715184302.v1.class)
|
|
|
+ public String selectItemList() 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("t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.erpitemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.assistance like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t1.explains like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("model") && !"".equals(whereObject.getString("model"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.model like'%").append(whereObject.getString("model")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("spec") && !"".equals(whereObject.getString("spec"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.spec like'%").append(whereObject.getString("spec")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("goodstype") && !"".equals(whereObject.getString("goodstype"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.goodstype like'%").append(whereObject.getString("goodstype")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("itemclassid") && !"".equals(whereObject.getString("itemclassid"))) {
|
|
|
+ Long itemclassid = whereObject.getLong("itemclassid");
|
|
|
+ ArrayList<Long> itemclassids = ItemClass.getSubItemClassIds(this, itemclassid);
|
|
|
+ itemclassids.add(itemclassid);
|
|
|
+ String sql = " and t1.itemid in( SELECT itemid from sa_itemsaleclass WHERE itemclassid in " + itemclassids + " and siteid='" + siteid + "')";
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+ where.append(sql);
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("sa_brandid") && !"".equals(whereObject.getString("sa_brandid"))) {
|
|
|
+ where.append(" and t1.itemid in( SELECT DISTINCT itemid from sa_itemsaleclass WHERE itemclassid in (SELECT itemclassid from plm_itemclass WHERE sa_brandid = " + whereObject.getLong("sa_brandid") + " and siteid = '" + siteid + "'))");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Long sa_trialid = content.getLongValue("sa_trialid");
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "plm_item",
|
|
|
+ "itemid", "itemno", "itemname", "model", "spec", "assistance", "goodstype", "explains", "marketprice", "orderminqty", "orderaddqty")
|
|
|
+ .setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_itemextend", "t2", "t2.itemid = t1.itemid AND t2.siteid = t1.siteid",
|
|
|
+ "erpitemname", "erpitemno");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t3", "t3.unitid = t1.unitid AND t3.siteid = t1.siteid");
|
|
|
+ querySQL.addQueryFields("unit", "t3.unitname");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setWhere("not exists(select 1 from sa_trialitems where sa_trialid=" + sa_trialid + " and itemid=t1.itemid and siteid='" + siteid + "' )");
|
|
|
+ querySQL.setPage(pageSize, pageNumber).setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ // 附件
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
|
|
|
+ // 商品品牌
|
|
|
+ RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids);
|
|
|
+ RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
|
|
|
+ //查询附件
|
|
|
+ RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids);
|
|
|
+ for (Row row : rows) {
|
|
|
+ row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
|
|
|
+ Rows brandRows = brandRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
+ Rows itemclassRows = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
+ row.put("brandname", StringUtils.join(brandRows.toArray("brandname"), ","));
|
|
|
+ row.put("itemclassname", StringUtils.join(itemclassRows.toArray("itemclassname"), ","));
|
|
|
+ }
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "申请试用明细新建或编辑", apiversion = R.ID2025110715293102.v1.class)
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+
|
|
|
+ Long sa_trialid = content.getLongValue("sa_trialid");
|
|
|
+
|
|
|
+ Rows rows = new trial(content).getTrialRow(sa_trialid);
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("试用申请不存在").toString();
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前状态不可添加").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONArray items = content.getJSONArray("items");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+
|
|
|
+ RowsMap orderItemsMap = dbConnect.runSqlQuery("SELECT * from sa_trialitems WHERE sa_trialid=" + sa_trialid + " and siteid='" + siteid + "'").toRowsMap("itemid");
|
|
|
+
|
|
|
+ for (Object obj : items) {
|
|
|
+ JSONObject item = (JSONObject) obj;
|
|
|
+ Long itemid = item.getLong("itemid");
|
|
|
+ Long sa_trialitemsid = item.getLong("sa_trialitemsid");
|
|
|
+ BigDecimal qty = item.getBigDecimalValue("qty");
|
|
|
+ if (orderItemsMap.containsKey(itemid.toString())) {
|
|
|
+ sa_trialitemsid = orderItemsMap.get(itemid.toString()).get(0).getLong("sa_trialitemsid");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sa_trialitemsid <= 0) {
|
|
|
+ sa_trialitemsid = createTableID("sa_trialitems");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_trialitems");
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setUniqueid(sa_trialitemsid);
|
|
|
+ insertSQL.setValue("sa_trialid", sa_trialid);
|
|
|
+ insertSQL.setValue("itemid", itemid);
|
|
|
+ insertSQL.setValue("qty", qty);
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ } else {
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_trialitems");
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setUniqueid(sa_trialitemsid);
|
|
|
+ updateSQL.setValue("qty", qty);
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "申请试用明细列表", apiversion = R.ID2025110715410702.v1.class)
|
|
|
+ public String listMX() 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.itemno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or 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(")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Long sa_trialid = content.getLongValue("sa_trialid");
|
|
|
+
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_trialitems",
|
|
|
+ "*");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t3", "t3.itemid = t1.itemid and t3.siteid = t1.siteid and t3.isshow=1",
|
|
|
+ "orderminqty_auxunit", "orderminqty", "orderaddqty_auxunit", "orderaddqty", "assistance", "goodstype", "explains","model","spec","marketprice","itemname","itemno");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "plm_itemextend", "t4", "t4.itemid = t1.itemid and t4.siteid = t1.siteid",
|
|
|
+ "erpitemname", "erpitemno");
|
|
|
+
|
|
|
+
|
|
|
+ querySQL.setWhere(where.toString());
|
|
|
+ querySQL.setWhere("t1.siteid", siteid);
|
|
|
+ querySQL.setWhere("t1.sa_trialid", sa_trialid);
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
|
|
|
+ // 商品品牌
|
|
|
+ RowsMap brandRowsMap = Brand.getBrandRowsMap(this, ids);
|
|
|
+ RowsMap itemclassRowsMap = ItemClass.getAllItemClassRowsMap(this, ids);
|
|
|
+ RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids);
|
|
|
+ for (Row row : rows) {
|
|
|
+ Rows brandRows = brandRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
+ Rows itemclassRows = itemclassRowsMap.getOrDefault(row.getString("itemid"), new Rows());
|
|
|
+ row.put("brandname", StringUtils.join(brandRows.toArray("brandname"), ","));
|
|
|
+ row.put("itemclassname", StringUtils.join(itemclassRows.toArray("itemclassname"), ","));
|
|
|
+ row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "申请试用明细删除", apiversion = R.ID2025110715414702.v1.class)
|
|
|
+ public String deleteMX() throws YosException {
|
|
|
+ Long sa_trialid = content.getLongValue("sa_trialid");
|
|
|
+ JSONArray sa_trialitemsids = content.getJSONArray("sa_trialitemsids");
|
|
|
+ Rows rows = new trial(content).getTrialRow(sa_trialid);
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("试用申请不存在").toString();
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("当前状态不可删除").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ DeleteSQL deleteSQL = SQLFactory.createDeleteSQL(this, "sa_trialitems");
|
|
|
+ deleteSQL.setSiteid(siteid);
|
|
|
+ deleteSQL.setWhere("sa_trialid", sa_trialid);
|
|
|
+ deleteSQL.setWhere("sa_trialitemsid", sa_trialitemsids);
|
|
|
+ dbConnect.runSqlUpdate(deleteSQL.getSQL());
|
|
|
+
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|