item.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. package restcontroller.crm.agent.item;
  2. import com.alibaba.fastjson2.JSONArray;
  3. import com.alibaba.fastjson2.JSONObject;
  4. import common.Controller;
  5. import common.YosException;
  6. import common.annotation.API;
  7. import common.annotation.Param;
  8. import common.data.*;
  9. import restcontroller.R;
  10. import java.util.ArrayList;
  11. @API(title = "美大CRM_经销商_商品管理")
  12. public class item extends Controller {
  13. public item(JSONObject content) throws YosException {
  14. super(content);
  15. }
  16. @API(title = "美大CRM_经销商_商品列表查询", type = API.Type.PageQuery, apiversion = R.ID2026031312441901.v1.class)
  17. public String sys_enterprise_item_querylist() throws YosException {
  18. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setTableAlias("t1");
  19. querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t2", "t1.unitid=t2.unitid", "unitname");
  20. querySQL.setSiteid(siteid);
  21. querySQL.setPage(pageSize, pageNumber);
  22. Rows rows = querySQL.query();
  23. return getSucReturnObject().setData(rows).toString();
  24. }
  25. @API(title = "美大CRM_经销商_商品详情查询", type = API.Type.Query, apiversion = R.ID2026031312515001.v1.class, params = {
  26. @Param(paramname = "sys_enterprise_itemid", fieldtype = FieldType.BigInt, remarks = "企业商品ID", isrequired = true)})
  27. public String sys_enterprise_item_querymain() throws YosException {
  28. long sys_enterprise_itemid = content.getLongValue("sys_enterprise_itemid");
  29. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setTableAlias("t1");
  30. querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t2", "t1.unitid=t2.unitid", "unitname");
  31. querySQL.setUniqueid(sys_enterprise_itemid);
  32. querySQL.setSiteid(siteid);
  33. Rows rows = querySQL.query();
  34. return getSucReturnObject().setData(rows).toString();
  35. }
  36. @API(title = "美大CRM_经销商_企业商品添加", apiversion = R.ID2026031313002101.v1.class, params = {
  37. @Param(paramname = "itemids", fieldtype = FieldType.JSON, remarks = "货品档案表ID,[1,2,3]", isrequired = true)})
  38. public String sys_enterprise_item_addfromsite() throws YosException {
  39. JSONArray itemids = content.getJSONArray("itemids");// 货品档案表ID
  40. QuerySQL sys_enterprise_itemQuery = SQLFactory.createQuerySQL(this, "sys_enterprise_item", "itemid");
  41. sys_enterprise_itemQuery.setSiteid(siteid);
  42. sys_enterprise_itemQuery.setWhere("sys_enterpriseid", sys_enterpriseid);
  43. sys_enterprise_itemQuery.setWhere("itemid", itemids);
  44. ArrayList<Long> sys_enterprise_itemids = sys_enterprise_itemQuery.query().toArrayList("itemid", new ArrayList<>());
  45. QuerySQL item_query = SQLFactory.createQuerySQL(this, "plm_item");
  46. item_query.setSiteid(siteid);
  47. item_query.setWhere("itemid", itemids);
  48. RowsMap plm_itemrowsMap = item_query.query().toRowsMap("itemid");
  49. SQLDump sqlDump = new SQLDump();
  50. for (int i = 0; i < itemids.size(); i++) {
  51. long itemid = itemids.getLongValue(i);
  52. if (!sys_enterprise_itemids.contains(itemid) && plm_itemrowsMap.containsKey(String.valueOf(itemid))) {
  53. Row itemrow = plm_itemrowsMap.get(String.valueOf(itemid)).getRow(0);
  54. double packageqty = itemrow.getDouble("packageqty");
  55. double safeqty = itemrow.getDouble("safeqty");
  56. String remarks = itemrow.getString("remarks");
  57. boolean ismodule = itemrow.getBoolean("ismodule");
  58. int warrantyday = itemrow.getInteger("warrantyday");
  59. String barcode = itemrow.getString("barcode");
  60. boolean skucontrol = itemrow.getBoolean("skucontrol");
  61. long grossweight = itemrow.getLong("grossweight");
  62. long weight = itemrow.getLong("weight");
  63. long unitid = itemrow.getLong("unitid");
  64. String itemno = itemrow.getString("itemno");
  65. String color = itemrow.getString("color");
  66. String spec = itemrow.getString("spec");
  67. String model = itemrow.getString("model");
  68. String itemname = itemrow.getString("itemname");
  69. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_item");
  70. insertSQL.setValue("siteid", siteid);// 站点
  71. insertSQL.setValue("itemid", itemid);// 货品档案表ID
  72. insertSQL.setValue("packing_qty", packageqty);// 包装数量
  73. insertSQL.setValue("safeqty", safeqty);// 安全库存
  74. insertSQL.setValue("remarks", remarks);// 说明
  75. insertSQL.setValue("ismodule", ismodule);// 是否配件
  76. insertSQL.setValue("warrantyday", warrantyday);// 保修期(年)
  77. insertSQL.setValue("barcode", barcode);// 商品条形码
  78. insertSQL.setValue("skucontrol", skucontrol);// 是否单品管理
  79. insertSQL.setValue("grossweight", grossweight);// 毛重(g)
  80. insertSQL.setValue("weight", weight);// 净重(g)
  81. insertSQL.setValue("unitid", unitid);// 计量单位
  82. insertSQL.setValue("itemno", itemno);// 产品编号
  83. insertSQL.setValue("prodtype", 1);// 商品类型
  84. insertSQL.setValue("color", color);// 颜色
  85. insertSQL.setValue("spec", spec);// 尺寸
  86. insertSQL.setValue("model", model);// 型号
  87. insertSQL.setValue("itemname", itemname);// 产品名称
  88. insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
  89. sqlDump.add(insertSQL);
  90. }
  91. }
  92. sqlDump.commit();
  93. return getSucReturnObject().toString();
  94. }
  95. @API(title = "美大CRM_经销商_自定义商品新增修改", apiversion = R.ID2026031312463301.v1.class, params = {
  96. @Param(paramname = "sys_enterprise_itemid", fieldtype = FieldType.BigInt, remarks = "企业商品ID", isrequired = true),
  97. @Param(paramname = "packing_qty", fieldtype = FieldType.Decimal, remarks = "包装数量", isrequired = true),
  98. @Param(paramname = "safeqty", fieldtype = FieldType.Decimal, remarks = "安全库存", isrequired = true),
  99. @Param(paramname = "remarks", fieldtype = FieldType.Varchar, remarks = "说明", isrequired = true),
  100. @Param(paramname = "ismodule", fieldtype = FieldType.Smallint, remarks = "是否配件", isrequired = true),
  101. @Param(paramname = "isabstract", fieldtype = FieldType.Smallint, remarks = "服务商品/虚拟商品", isrequired = true),
  102. @Param(paramname = "warrantyday", fieldtype = FieldType.Int, remarks = "保修期(年)", isrequired = true),
  103. @Param(paramname = "barcode", fieldtype = FieldType.Varchar, remarks = "商品条形码", isrequired = true),
  104. @Param(paramname = "guid_price_cus", fieldtype = FieldType.Decimal, remarks = "指导价(站点自定义)", isrequired = true),
  105. @Param(paramname = "grossweight", fieldtype = FieldType.BigInt, remarks = "毛重(g)", isrequired = true),
  106. @Param(paramname = "weight", fieldtype = FieldType.BigInt, remarks = "净重(g)", isrequired = true),
  107. @Param(paramname = "unitid", fieldtype = FieldType.BigInt, remarks = "计量单位", isrequired = true),
  108. @Param(paramname = "itemno_cus", fieldtype = FieldType.Varchar, remarks = "站点商品编码", isrequired = true),
  109. @Param(paramname = "color", fieldtype = FieldType.Varchar, remarks = "颜色", isrequired = true),
  110. @Param(paramname = "spec", fieldtype = FieldType.Varchar, remarks = "尺寸", isrequired = true),
  111. @Param(paramname = "model", fieldtype = FieldType.Varchar, remarks = "型号", isrequired = true),
  112. @Param(paramname = "itemname", fieldtype = FieldType.Varchar, remarks = "产品名称", isrequired = true)})
  113. public String sys_enterprise_item_save() throws YosException {
  114. long sys_enterprise_itemid = content.getLongValue("sys_enterprise_itemid");
  115. double packing_qty = content.getDoubleValue("packing_qty");// 包装数量
  116. double safeqty = content.getDoubleValue("safeqty");// 安全库存
  117. String remarks = content.getStringValue("remarks");// 说明
  118. boolean ismodule = content.getBooleanValue("ismodule");// 是否配件
  119. boolean isabstract = content.getBooleanValue("isabstract");// 服务商品/虚拟商品
  120. long warrantyday = content.getLongValue("warrantyday");// 保修期(年)
  121. String barcode = content.getStringValue("barcode");// 商品条形码
  122. double guid_price_cus = content.getDoubleValue("guid_price_cus");// 指导价(站点自定义)
  123. long grossweight = content.getLongValue("grossweight");// 毛重(g)
  124. long weight = content.getLongValue("weight");// 净重(g)
  125. long unitid = content.getLongValue("unitid");// 计量单位
  126. String itemno_cus = content.getString("itemno_cus");// 站点商品编码
  127. String color = content.getStringValue("color");// 颜色
  128. String spec = content.getStringValue("spec");// 尺寸
  129. String model = content.getStringValue("model");// 型号
  130. String itemname = content.getStringValue("itemname");// 产品名称
  131. Rows sys_enterprise_itemRows = SQLFactory.createQuerySQL(this, "sys_enterprise_item", "sys_enterprise_itemid").setSiteid(siteid).setUniqueid(sys_enterprise_itemid).query();
  132. SQLDump sqldump = new SQLDump();
  133. if (sys_enterprise_itemid == 0 || sys_enterprise_itemRows.isEmpty()) {
  134. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setWhere("itemno_cus", itemno_cus).setSiteid(siteid).setWhere("sys_enterpriseid", sys_enterpriseid);
  135. if (querySQL.query().isNotEmpty()) {
  136. return getErrReturnObject().setErrMsg("商品编码" + itemno_cus + "已存在").toString();
  137. }
  138. InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sys_enterprise_item");
  139. insertSQL.setValue("siteid", siteid);// 站点
  140. insertSQL.setValue("packing_qty", packing_qty);// 包装数量
  141. insertSQL.setValue("safeqty", safeqty);// 安全库存
  142. insertSQL.setValue("remarks", remarks);// 说明
  143. insertSQL.setValue("ismodule", ismodule);// 是否配件
  144. insertSQL.setValue("isabstract", isabstract);// 服务商品/虚拟商品
  145. insertSQL.setValue("warrantyday", warrantyday);// 保修期(年)
  146. insertSQL.setValue("barcode", barcode);// 商品条形码
  147. insertSQL.setValue("guid_price_cus", guid_price_cus);// 指导价(站点自定义)
  148. insertSQL.setValue("grossweight", grossweight);// 毛重(g)
  149. insertSQL.setValue("weight", weight);// 净重(g)
  150. insertSQL.setValue("unitid", unitid);// 单位名称
  151. insertSQL.setValue("itemno_cus", itemno_cus);// 站点商品编码
  152. insertSQL.setValue("itemno", userInfo.getAgentRow().getString("agentnum") + itemno_cus);// 产品编号
  153. insertSQL.setValue("prodtype", 2);// 商品类型
  154. insertSQL.setValue("color", color);// 颜色
  155. insertSQL.setValue("spec", spec);// 尺寸
  156. insertSQL.setValue("model", model);// 型号
  157. insertSQL.setValue("itemname", itemname);// 产品名称
  158. insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);// 合作企业档案ID
  159. sqldump.add(insertSQL);
  160. } else {
  161. UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sys_enterprise_item");
  162. updateSQL.setValue("packing_qty", packing_qty);// 包装数量
  163. updateSQL.setValue("safeqty", safeqty);// 安全库存
  164. updateSQL.setValue("remarks", remarks);// 说明
  165. updateSQL.setValue("ismodule", ismodule);// 是否配件
  166. updateSQL.setValue("isabstract", isabstract);// 服务商品/虚拟商品
  167. updateSQL.setValue("warrantyday", warrantyday);// 保修期(年)
  168. updateSQL.setValue("barcode", barcode);// 商品条形码
  169. updateSQL.setValue("grossweight", grossweight);// 毛重(g)
  170. updateSQL.setValue("weight", weight);// 净重(g)
  171. updateSQL.setValue("unitid", unitid);// 单位名称
  172. updateSQL.setValue("color", color);// 颜色
  173. updateSQL.setValue("spec", spec);// 尺寸
  174. updateSQL.setValue("model", model);// 型号
  175. updateSQL.setValue("itemname", itemname);// 产品名称
  176. updateSQL.setValue("guid_price_cus", guid_price_cus);// 指导价(站点自定义)
  177. updateSQL.setSiteid(siteid);
  178. updateSQL.setUniqueid(sys_enterprise_itemid);
  179. sqldump.add(updateSQL);
  180. }
  181. sqldump.commit();
  182. return getSucReturnObject().toString();
  183. }
  184. @API(title = "美大CRM_经销商_商品上下架", apiversion = R.ID2026031315384901.v1.class, params = {
  185. @Param(paramname = "sys_enterprise_itemids", fieldtype = FieldType.JSON, remarks = "企业商品ID,[1,2,3]", isrequired = true),
  186. @Param(paramname = "isonsale", fieldtype = FieldType.Smallint, remarks = "是否上架", isrequired = true)})
  187. public String sys_enterprise_item_onsale() throws YosException {
  188. JSONArray sys_enterprise_itemids = content.getJSONArray("sys_enterprise_itemids");
  189. boolean isonsale = content.getBooleanValue("isonsale");
  190. UpdateSQL querySQL = SQLFactory.createUpdateSQL(this, "sys_enterprise_item");
  191. querySQL.setSiteid(siteid);
  192. querySQL.setValue("isonsale", isonsale);
  193. querySQL.setWhere("sys_enterprise_itemid", sys_enterprise_itemids);
  194. querySQL.update();
  195. return getSucReturnObject().toString();
  196. }
  197. @API(title = "美大CRM_经销商_商品删除", apiversion = R.ID2026031712364501.v1.class, params = {
  198. @Param(paramname = "sys_enterprise_itemids", fieldtype = FieldType.JSON, remarks = "企业商品ID,[1,2,3]", isrequired = true)})
  199. public String sys_enterprise_item_delete() throws YosException {
  200. JSONArray sys_enterprise_itemids = content.getJSONArray("sys_enterprise_itemids");
  201. for (int i = 0; i < sys_enterprise_itemids.size(); i++) {
  202. long sys_enterprise_itemid = sys_enterprise_itemids.getLongValue(i);
  203. Rows enterprise_itemRows = SQLFactory.createQuerySQL(this, "sys_enterprise_item").setWhere("isonsale", true).setUniqueid(sys_enterprise_itemid).query();
  204. if (enterprise_itemRows.isNotEmpty()) {
  205. return getErrReturnObject().setErrMsg("商品" + enterprise_itemRows.getRow(0).getString("itemname") + "已上架,请先下架").toString();
  206. }
  207. Rows custorderitemsRows = SQLFactory.createQuerySQL(this, "sa_custorderitems").setWhere("sys_enterprise_itemid", sys_enterprise_itemid).setPage(1, 1).query();
  208. if (custorderitemsRows.isNotEmpty()) {
  209. return getErrReturnObject().setErrMsg("商品" + enterprise_itemRows.getRow(0).getString("itemname") + "已存在订单,无法删除").toString();
  210. }
  211. QuerySQL invbalQuery = SQLFactory.createQuerySQL(this, "sys_enterprise_invbal");
  212. invbalQuery.setSiteid(siteid);
  213. invbalQuery.setWhere("sys_enterprise_itemid", sys_enterprise_itemid);
  214. if (!invbalQuery.query().isEmpty()) {
  215. return getErrReturnObject().setErrMsg("该商品存在库存,不可删除!").toString();
  216. }
  217. SQLFactory.createDeleteSQL(this, "sys_enterprise_item").setSiteid(siteid).setWhere("sys_enterprise_itemid", sys_enterprise_itemid).delete();
  218. }
  219. return getSucReturnObject().toString();
  220. }
  221. }