package restcontroller.crm.agent.item; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import common.Controller; import common.YosException; import common.annotation.API; import common.annotation.Param; import common.data.*; import restcontroller.R; import java.util.ArrayList; @API(title = "美大CRM_经销商_商品管理") public class item extends Controller { public item(JSONObject content) throws YosException { super(content); } @API(title = "美大CRM_经销商_商品列表查询", type = API.Type.PageQuery, apiversion = R.ID2026031312441901.v1.class) public String sys_enterprise_item_querylist() throws YosException { QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setTableAlias("t1"); querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t2", "t1.unitid=t2.unitid", "unitname"); querySQL.setSiteid(siteid); querySQL.setPage(pageSize, pageNumber); Rows rows = querySQL.query(); return getSucReturnObject().setData(rows).toString(); } @API(title = "美大CRM_经销商_商品详情查询", type = API.Type.Query, apiversion = R.ID2026031312515001.v1.class, params = { @Param(paramname = "sys_enterprise_itemid", fieldtype = FieldType.BigInt, remarks = "企业商品ID", isrequired = true)}) public String sys_enterprise_item_querymain() throws YosException { long sys_enterprise_itemid = content.getLongValue("sys_enterprise_itemid"); QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setTableAlias("t1"); querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t2", "t1.unitid=t2.unitid", "unitname"); querySQL.setUniqueid(sys_enterprise_itemid); querySQL.setSiteid(siteid); Rows rows = querySQL.query(); return getSucReturnObject().setData(rows).toString(); } @API(title = "美大CRM_经销商_企业商品添加", apiversion = R.ID2026031313002101.v1.class, params = { @Param(paramname = "itemids", fieldtype = FieldType.JSON, remarks = "货品档案表ID,[1,2,3]", isrequired = true)}) public String sys_enterprise_item_addfromsite() throws YosException { JSONArray itemids = content.getJSONArray("itemids");// 货品档案表ID QuerySQL sys_enterprise_itemQuery = SQLFactory.createQuerySQL(this, "sys_enterprise_item", "itemid"); sys_enterprise_itemQuery.setSiteid(siteid); sys_enterprise_itemQuery.setWhere("sys_enterpriseid", sys_enterpriseid); sys_enterprise_itemQuery.setWhere("itemid", itemids); ArrayList sys_enterprise_itemids = sys_enterprise_itemQuery.query().toArrayList("itemid", new ArrayList<>()); QuerySQL item_query = SQLFactory.createQuerySQL(this, "plm_item"); item_query.setSiteid(siteid); item_query.setWhere("itemid", itemids); RowsMap plm_itemrowsMap = item_query.query().toRowsMap("itemid"); SQLDump sqlDump = new SQLDump(); for (int i = 0; i < itemids.size(); i++) { long itemid = itemids.getLongValue(i); if (!sys_enterprise_itemids.contains(itemid) && plm_itemrowsMap.containsKey(String.valueOf(itemid))) { Row itemrow = plm_itemrowsMap.get(String.valueOf(itemid)).getRow(0); double packageqty = itemrow.getDouble("packageqty"); double safeqty = itemrow.getDouble("safeqty"); String remarks = itemrow.getString("remarks"); boolean ismodule = itemrow.getBoolean("ismodule"); int warrantyday = itemrow.getInteger("warrantyday"); String barcode = itemrow.getString("barcode"); boolean skucontrol = itemrow.getBoolean("skucontrol"); long grossweight = itemrow.getLong("grossweight"); long weight = itemrow.getLong("weight"); long unitid = itemrow.getLong("unitid"); String itemno = itemrow.getString("itemno"); String color = itemrow.getString("color"); String spec = itemrow.getString("spec"); String model = itemrow.getString("model"); String itemname = itemrow.getString("itemname"); InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_item"); insertSQL.setValue("siteid", siteid);// 站点 insertSQL.setValue("itemid", itemid);// 货品档案表ID insertSQL.setValue("packing_qty", packageqty);// 包装数量 insertSQL.setValue("safeqty", safeqty);// 安全库存 insertSQL.setValue("remarks", remarks);// 说明 insertSQL.setValue("ismodule", ismodule);// 是否配件 insertSQL.setValue("warrantyday", warrantyday);// 保修期(年) insertSQL.setValue("barcode", barcode);// 商品条形码 insertSQL.setValue("skucontrol", skucontrol);// 是否单品管理 insertSQL.setValue("grossweight", grossweight);// 毛重(g) insertSQL.setValue("weight", weight);// 净重(g) insertSQL.setValue("unitid", unitid);// 计量单位 insertSQL.setValue("itemno", itemno);// 产品编号 insertSQL.setValue("prodtype", 1);// 商品类型 insertSQL.setValue("color", color);// 颜色 insertSQL.setValue("spec", spec);// 尺寸 insertSQL.setValue("model", model);// 型号 insertSQL.setValue("itemname", itemname);// 产品名称 insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID sqlDump.add(insertSQL); } } sqlDump.commit(); return getSucReturnObject().toString(); } @API(title = "美大CRM_经销商_自定义商品新增修改", apiversion = R.ID2026031312463301.v1.class, params = { @Param(paramname = "sys_enterprise_itemid", fieldtype = FieldType.BigInt, remarks = "企业商品ID", isrequired = true), @Param(paramname = "packing_qty", fieldtype = FieldType.Decimal, remarks = "包装数量", isrequired = true), @Param(paramname = "safeqty", fieldtype = FieldType.Decimal, remarks = "安全库存", isrequired = true), @Param(paramname = "remarks", fieldtype = FieldType.Varchar, remarks = "说明", isrequired = true), @Param(paramname = "ismodule", fieldtype = FieldType.Smallint, remarks = "是否配件", isrequired = true), @Param(paramname = "isabstract", fieldtype = FieldType.Smallint, remarks = "服务商品/虚拟商品", isrequired = true), @Param(paramname = "warrantyday", fieldtype = FieldType.Int, remarks = "保修期(年)", isrequired = true), @Param(paramname = "barcode", fieldtype = FieldType.Varchar, remarks = "商品条形码", isrequired = true), @Param(paramname = "guid_price_cus", fieldtype = FieldType.Decimal, remarks = "指导价(站点自定义)", isrequired = true), @Param(paramname = "grossweight", fieldtype = FieldType.BigInt, remarks = "毛重(g)", isrequired = true), @Param(paramname = "weight", fieldtype = FieldType.BigInt, remarks = "净重(g)", isrequired = true), @Param(paramname = "unitid", fieldtype = FieldType.BigInt, remarks = "计量单位", isrequired = true), @Param(paramname = "itemno_cus", fieldtype = FieldType.Varchar, remarks = "站点商品编码", isrequired = true), @Param(paramname = "color", fieldtype = FieldType.Varchar, remarks = "颜色", isrequired = true), @Param(paramname = "spec", fieldtype = FieldType.Varchar, remarks = "尺寸", isrequired = true), @Param(paramname = "model", fieldtype = FieldType.Varchar, remarks = "型号", isrequired = true), @Param(paramname = "itemname", fieldtype = FieldType.Varchar, remarks = "产品名称", isrequired = true)}) public String sys_enterprise_item_save() throws YosException { long sys_enterprise_itemid = content.getLongValue("sys_enterprise_itemid"); double packing_qty = content.getDoubleValue("packing_qty");// 包装数量 double safeqty = content.getDoubleValue("safeqty");// 安全库存 String remarks = content.getStringValue("remarks");// 说明 boolean ismodule = content.getBooleanValue("ismodule");// 是否配件 boolean isabstract = content.getBooleanValue("isabstract");// 服务商品/虚拟商品 long warrantyday = content.getLongValue("warrantyday");// 保修期(年) String barcode = content.getStringValue("barcode");// 商品条形码 double guid_price_cus = content.getDoubleValue("guid_price_cus");// 指导价(站点自定义) long grossweight = content.getLongValue("grossweight");// 毛重(g) long weight = content.getLongValue("weight");// 净重(g) long unitid = content.getLongValue("unitid");// 计量单位 String itemno_cus = content.getString("itemno_cus");// 站点商品编码 String color = content.getStringValue("color");// 颜色 String spec = content.getStringValue("spec");// 尺寸 String model = content.getStringValue("model");// 型号 String itemname = content.getStringValue("itemname");// 产品名称 Rows sys_enterprise_itemRows = SQLFactory.createQuerySQL(this, "sys_enterprise_item", "sys_enterprise_itemid").setSiteid(siteid).setUniqueid(sys_enterprise_itemid).query(); SQLDump sqldump = new SQLDump(); if (sys_enterprise_itemid == 0 || sys_enterprise_itemRows.isEmpty()) { QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setWhere("itemno_cus", itemno_cus).setSiteid(siteid).setWhere("sys_enterpriseid", sys_enterpriseid); if (querySQL.query().isNotEmpty()) { return getErrReturnObject().setErrMsg("商品编码" + itemno_cus + "已存在").toString(); } InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_item"); insertSQL.setValue("siteid", siteid);// 站点 insertSQL.setValue("packing_qty", packing_qty);// 包装数量 insertSQL.setValue("safeqty", safeqty);// 安全库存 insertSQL.setValue("remarks", remarks);// 说明 insertSQL.setValue("ismodule", ismodule);// 是否配件 insertSQL.setValue("isabstract", isabstract);// 服务商品/虚拟商品 insertSQL.setValue("warrantyday", warrantyday);// 保修期(年) insertSQL.setValue("barcode", barcode);// 商品条形码 insertSQL.setValue("guid_price_cus", guid_price_cus);// 指导价(站点自定义) insertSQL.setValue("grossweight", grossweight);// 毛重(g) insertSQL.setValue("weight", weight);// 净重(g) insertSQL.setValue("unitid", unitid);// 单位名称 insertSQL.setValue("itemno_cus", itemno_cus);// 站点商品编码 insertSQL.setValue("itemno", userInfo.getAgentRow().getString("agentnum") + itemno_cus);// 产品编号 insertSQL.setValue("prodtype", 2);// 商品类型 insertSQL.setValue("color", color);// 颜色 insertSQL.setValue("spec", spec);// 尺寸 insertSQL.setValue("model", model);// 型号 insertSQL.setValue("itemname", itemname);// 产品名称 insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID sqldump.add(insertSQL); } else { UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_enterprise_item"); updateSQL.setValue("packing_qty", packing_qty);// 包装数量 updateSQL.setValue("safeqty", safeqty);// 安全库存 updateSQL.setValue("remarks", remarks);// 说明 updateSQL.setValue("ismodule", ismodule);// 是否配件 updateSQL.setValue("isabstract", isabstract);// 服务商品/虚拟商品 updateSQL.setValue("warrantyday", warrantyday);// 保修期(年) updateSQL.setValue("barcode", barcode);// 商品条形码 updateSQL.setValue("grossweight", grossweight);// 毛重(g) updateSQL.setValue("weight", weight);// 净重(g) updateSQL.setValue("unitid", unitid);// 单位名称 updateSQL.setValue("color", color);// 颜色 updateSQL.setValue("spec", spec);// 尺寸 updateSQL.setValue("model", model);// 型号 updateSQL.setValue("itemname", itemname);// 产品名称 updateSQL.setValue("guid_price_cus", guid_price_cus);// 指导价(站点自定义) updateSQL.setSiteid(siteid); updateSQL.setUniqueid(sys_enterprise_itemid); sqldump.add(updateSQL); } sqldump.commit(); return getSucReturnObject().toString(); } @API(title = "美大CRM_经销商_商品上下架", apiversion = R.ID2026031315384901.v1.class, params = { @Param(paramname = "sys_enterprise_itemids", fieldtype = FieldType.JSON, remarks = "企业商品ID,[1,2,3]", isrequired = true), @Param(paramname = "isonsale", fieldtype = FieldType.Smallint, remarks = "是否上架", isrequired = true)}) public String sys_enterprise_item_onsale() throws YosException { JSONArray sys_enterprise_itemids = content.getJSONArray("sys_enterprise_itemids"); boolean isonsale = content.getBooleanValue("isonsale"); UpdateSQL querySQL = SQLFactory.createUpdateSQL(this, "sys_enterprise_item"); querySQL.setSiteid(siteid); querySQL.setValue("isonsale", isonsale); querySQL.setWhere("sys_enterprise_itemid", sys_enterprise_itemids); querySQL.update(); return getSucReturnObject().toString(); } @API(title = "美大CRM_经销商_商品删除", apiversion = R.ID2026031712364501.v1.class, params = { @Param(paramname = "sys_enterprise_itemids", fieldtype = FieldType.JSON, remarks = "企业商品ID,[1,2,3]", isrequired = true)}) public String sys_enterprise_item_delete() throws YosException { JSONArray sys_enterprise_itemids = content.getJSONArray("sys_enterprise_itemids"); for (int i = 0; i < sys_enterprise_itemids.size(); i++) { long sys_enterprise_itemid = sys_enterprise_itemids.getLongValue(i); Rows enterprise_itemRows = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setWhere("isonsale", true).setUniqueid(sys_enterprise_itemid).query(); if (enterprise_itemRows.isNotEmpty()) { return getErrReturnObject().setErrMsg("商品" + enterprise_itemRows.getRow(0).getString("itemname") + "已上架,请先下架").toString(); } Rows custorderitemsRows = SQLFactory.createQuerySQL(this, "sa_custorderitems").setWhere("sys_enterprise_itemid", sys_enterprise_itemid).setPage(1, 1).query(); if (custorderitemsRows.isNotEmpty()) { return getErrReturnObject().setErrMsg("商品" + enterprise_itemRows.getRow(0).getString("itemname") + "已存在订单,无法删除").toString(); } QuerySQL invbalQuery = SQLFactory.createQuerySQL(this, "sys_enterprise_invbal"); invbalQuery.setSiteid(siteid); invbalQuery.setWhere("sys_enterprise_itemid", sys_enterprise_itemid); if (!invbalQuery.query().isEmpty()) { return getErrReturnObject().setErrMsg("该商品存在库存,不可删除!").toString(); } SQLFactory.createDeleteSQL(this, "sys_enterprise_item").setSiteid(siteid).setWhere("sys_enterprise_itemid", sys_enterprise_itemid).delete(); } return getSucReturnObject().toString(); } }