accountclass.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. package restcontroller.webmanage.sale.accountclass;
  2. import beans.data.BatchDeleteErr;
  3. import com.alibaba.fastjson.JSONArray;
  4. import com.alibaba.fastjson.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.annotation.CACHEING;
  9. import common.annotation.CACHEING_CLEAN;
  10. import common.annotation.cm;
  11. import common.data.Row;
  12. import common.data.Rows;
  13. import common.data.SQLFactory;
  14. import restcontroller.R;
  15. import restcontroller.sale.creditbill.creditbill;
  16. import java.math.BigDecimal;
  17. import java.util.ArrayList;
  18. @API(title = "营销账户类型")
  19. public class accountclass extends Controller {
  20. public accountclass(JSONObject content) throws YosException {
  21. super(content);
  22. // TODO Auto-generated constructor stub
  23. }
  24. /**
  25. * 新增修改营销账户类型
  26. *
  27. * @return
  28. */
  29. @API(title = "营销账户类型新增修改", apiversion = R.ID20221008134703.v1.class)
  30. @CACHEING_CLEAN(cms = {@cm(clazz = accountclass.class, method = {"queryAccountclass"}), @cm(clazz = creditbill.class, method = {"queryAccountclassList"})})
  31. public String insertormodify_accountclass() throws YosException {
  32. long sa_accountclassid = content.getLong("sa_accountclassid");
  33. String accountno = content.getString("accountno");
  34. String accountname = content.getString("accountname");
  35. boolean isorder = content.getBoolean("isorder");
  36. boolean isrebate = content.getBooleanValue("isrebate");
  37. JSONArray bindingcategories =content.getJSONArray("bindingcategories");
  38. BigDecimal maximumdiscount = content.getBigDecimalValue("maximumdiscount");
  39. ArrayList<String> sqllist = new ArrayList<>();
  40. if (sa_accountclassid <= 0 || dbConnect
  41. .runSqlQuery(
  42. "select sa_accountclassid from sa_accountclass where sa_accountclassid=" + sa_accountclassid)
  43. .isEmpty()) {
  44. Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM sa_accountclass WHERE accountno = '"
  45. + accountno + "' and siteid='" + siteid + "'");
  46. if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
  47. return getErrReturnObject().setErrMsg("营销账户类型已存在").toString();
  48. }
  49. SQLFactory sqlAddFactory = new SQLFactory(this, "营销账户类型新增");
  50. sa_accountclassid = createTableID("sa_accountclass");
  51. sqlAddFactory.addParameter("sa_accountclassid", sa_accountclassid);
  52. sqlAddFactory.addParameter("siteid", siteid);
  53. sqlAddFactory.addParameter("accountno", accountno);
  54. sqlAddFactory.addParameter("accountname", accountname);
  55. sqlAddFactory.addParameter("isorder", isorder);
  56. sqlAddFactory.addParameter("isrebate", isrebate);
  57. sqlAddFactory.addParameter("maximumdiscount", maximumdiscount);
  58. sqlAddFactory.addParameter("bindingcategories", bindingcategories);
  59. content.put("sa_accountclassid", sa_accountclassid);
  60. sqllist.add(sqlAddFactory.getSQL());
  61. } else {
  62. Rows rows = dbConnect.runSqlQuery("SELECT COUNT(*) count FROM sa_accountclass WHERE sa_accountclassid!="
  63. + content.getLong("sa_accountclassid") + " and accountno = '" + accountno + "' and siteid='"
  64. + siteid + "'");
  65. if (!rows.isEmpty() && rows.get(0).getLong("count") > 0) {
  66. return getErrReturnObject().setErrMsg("营销账户类型已存在").toString();
  67. }
  68. Rows isuserdRows = dbConnect
  69. .runSqlQuery(
  70. "select isused,accountno,accountname,isorder from sa_accountclass where sa_accountclassid=" + sa_accountclassid);
  71. SQLFactory sqlUpdateFactory = new SQLFactory(this, "营销账户类型更新");
  72. sqlUpdateFactory.addParameter("sa_accountclassid", content.getLong("sa_accountclassid"));
  73. sqlUpdateFactory.addParameter("siteid", siteid);
  74. if (isuserdRows.get(0).getBoolean("isused")) {
  75. if (!content.getBoolean("isused")) {
  76. Rows rowscashbill = dbConnect.runSqlQuery("select sa_cashbillid from sa_cashbill where sa_accountclassid="
  77. + sa_accountclassid + " and status='审核'");
  78. Rows rowsaccountbalance = dbConnect.runSqlQuery(
  79. "select sa_accountbalanceid from sa_accountbalance where sa_accountclassid=" + sa_accountclassid);
  80. if (!rowscashbill.isEmpty() || !rowsaccountbalance.isEmpty()) {
  81. return getErrReturnObject().setErrMsg("此营销账户类型已被使用,无法反启用").toString();
  82. }
  83. }
  84. sqlUpdateFactory.addParameter("accountno", accountno);
  85. sqlUpdateFactory.addParameter("accountname", accountname);
  86. sqlUpdateFactory.addParameter("isorder", isorder);
  87. sqlUpdateFactory.addParameter("isused", content.getInteger("isused"));
  88. sqlUpdateFactory.addParameter("isrebate", isuserdRows.get(0).getInteger("isrebate"));
  89. sqlUpdateFactory.addParameter("maximumdiscount", maximumdiscount);
  90. sqlUpdateFactory.addParameter("bindingcategories", bindingcategories);
  91. } else {
  92. if (content.getInteger("isused") == 1 && isrebate) {
  93. sqllist.add("update sa_accountclass set isrebate=0 where sa_accountclassid !=" + sa_accountclassid);
  94. }
  95. sqlUpdateFactory.addParameter("accountno", accountno);
  96. sqlUpdateFactory.addParameter("accountname", accountname);
  97. sqlUpdateFactory.addParameter("isorder", isorder);
  98. sqlUpdateFactory.addParameter("isused", content.getInteger("isused"));
  99. sqlUpdateFactory.addParameter("isrebate", isrebate);
  100. sqlUpdateFactory.addParameter("maximumdiscount", maximumdiscount);
  101. sqlUpdateFactory.addParameter("bindingcategories", bindingcategories);
  102. }
  103. sqllist.add(sqlUpdateFactory.getSQL());
  104. }
  105. dbConnect.runSqlUpdate(sqllist);
  106. return queryAccountclass();
  107. }
  108. /**
  109. * 查询营销大类
  110. *
  111. * @return
  112. */
  113. @API(title = "查询营销大类", apiversion = R.ID20230711135303.v1.class)
  114. @CACHEING
  115. public String queryitemclassTop() throws YosException {
  116. /*
  117. * SQL通告板块查询参数设置并查询
  118. */
  119. SQLFactory factory = new SQLFactory(this, "营销大类列表查询");
  120. factory.addParameter("siteid", siteid);
  121. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  122. return getSucReturnObject().setData(rows).toString();
  123. }
  124. /**
  125. * 查询营销账户类型
  126. *
  127. * @return
  128. */
  129. @API(title = "查询营销账户类型", apiversion = R.ID20221008134803.v1.class)
  130. public String queryAccountclass() throws YosException {
  131. /*
  132. * 过滤条件设置
  133. */
  134. String where = " 1=1 ";
  135. if (content.containsKey("where")) {
  136. JSONObject whereObject = content.getJSONObject("where");
  137. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  138. where = where + " and(accountname like'%" + whereObject.getString("condition")
  139. + "%' or accountno like '%" + whereObject.getString("condition") + "%')";
  140. }
  141. if (whereObject.containsKey("isused") && !"".equals(whereObject.getString("isused"))) {
  142. where = where + " and t1.isused=" + whereObject.getLong("isused");
  143. }
  144. if (whereObject.containsKey("isorder") && !"".equals(whereObject.getString("isorder"))) {
  145. where = where + " and t1.isorder=" + whereObject.getLong("isorder");
  146. }
  147. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  148. where = where + " and t1.isrebate=" + whereObject.getLong("isrebate");
  149. }
  150. if (whereObject.containsKey("isnotspecialfund") && !"".equals(whereObject.getString("isnotspecialfund"))) {
  151. where = where + " and (JSON_TYPE(t1.bindingcategories) = 'NULL' || JSON_LENGTH(t1.bindingcategories) = 0) and t1.accountname !='保证金账户' ";
  152. }
  153. }
  154. if(content.containsKey("sys_enterpriseid")){
  155. sys_enterpriseid=content.getLongValue("sys_enterpriseid");
  156. }
  157. /*
  158. * SQL通告板块查询参数设置并查询
  159. */
  160. SQLFactory factory = new SQLFactory(this, "营销账户类型列表查询");
  161. factory.addParameter("siteid", siteid);
  162. factory.addParameter("sys_enterpriseid", sys_enterpriseid);
  163. factory.addParameter_SQL("where", where);
  164. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  165. // for (Row row:rows) {
  166. // JSONArray bindingcategories= row.getJSONArray("bindingcategories");
  167. // if(bindingcategories.size()>0){
  168. // Rows itemclassRows = dbConnect.runSqlQuery("select * from plm_itemclass where siteid='"+siteid+"' and classtype='营销' and itemclassid in"+bindingcategories.toJSONString().replace("[", "(").replace("]", ")"));
  169. // row.put("bindingcategories",itemclassRows.toJsonArray("itemclassname"));
  170. // }else{
  171. // row.put("bindingcategories",new JSONArray());
  172. // }
  173. // }
  174. return getSucReturnObject().setData(rows).toString();
  175. }
  176. /**
  177. * 查询营销账户余额
  178. *
  179. * @return
  180. */
  181. @API(title = "查询营销账户余额", apiversion = R.ID20221008145903.v1.class)
  182. @CACHEING
  183. public String queryAccountbalance() throws YosException {
  184. long type = content.getLongValue("type");
  185. /*
  186. 过滤条件设置
  187. */
  188. String where = " 1=1 ";
  189. if (content.containsKey("where")) {
  190. JSONObject whereObject = content.getJSONObject("where");
  191. if (whereObject.containsKey("sys_enterpriseid") && !"".equals(whereObject.getString("sys_enterpriseid"))) {
  192. where = where + " and t1.sys_enterpriseid='" + whereObject.getString("sys_enterpriseid") + "' ";
  193. }
  194. if (whereObject.containsKey("enterprisename") && !"".equals(whereObject.getString("enterprisename"))) {
  195. where = where + " and t3.enterprisename='" + whereObject.getString("enterprisename") + "' ";
  196. }
  197. if (whereObject.containsKey("accountno") && !"".equals(whereObject.getString("accountno"))) {
  198. where = where + " and t2.accountno='" + whereObject.getString("accountno") + "' ";
  199. }
  200. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  201. where = where + " and t2.accountname='" + whereObject.getString("accountname") + "' ";
  202. }
  203. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  204. where = where + " and (t2.accountname like'%" + whereObject.getString("condition") + "%' " +
  205. "or t3.enterprisename like'%" + whereObject.getString("condition") + "%' " +
  206. "or t4.agentnum like'%" + whereObject.getString("condition") + "%' " +
  207. ") ";
  208. }
  209. }
  210. if (type == 1) {
  211. where = where + " and t1.sys_enterpriseid='" + sys_enterpriseid + "' ";
  212. }
  213. /*
  214. * SQL通告板块查询参数设置并查询
  215. */
  216. SQLFactory factory = new SQLFactory(this, "营销账户余额查询", pageSize, pageNumber, pageSorting);
  217. factory.addParameter("siteid", siteid);
  218. factory.addParameter_SQL("where", where);
  219. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  220. if (!rows.isEmpty()) {
  221. for (Row row : rows) {
  222. row.put("balance", row.getBigDecimal("balance"));
  223. row.put("creditquota", row.getBigDecimal("creditquota"));
  224. }
  225. }
  226. return getSucReturnObject().setData(rows).toString();
  227. }
  228. @API(title = "删除", apiversion = R.ID20221008134903.v1.class)
  229. @CACHEING_CLEAN(cms = {@cm(clazz = accountclass.class, method = {"queryAccountclass"}), @cm(clazz = creditbill.class, method = {"queryAccountclassList"})})
  230. public String delete() throws YosException {
  231. JSONArray sa_accountclassids = content.getJSONArray("sa_accountclassids");
  232. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_accountclassids.size());
  233. for (Object o : sa_accountclassids) {
  234. long sa_accountclassid = Long.parseLong(o.toString());
  235. Rows RowsStatus = dbConnect.runSqlQuery("select sa_accountclassid,isused from sa_accountclass where siteid='"
  236. + siteid + "' and sa_accountclassid='" + sa_accountclassid + "'");
  237. if (RowsStatus.isNotEmpty()) {
  238. if (RowsStatus.get(0).getBoolean("isused")) {
  239. batchDeleteErr.addErr(sa_accountclassid, "此营销账户类型已启用,无法删除");
  240. continue;
  241. }
  242. // 判断账户类型是否被使用(存在收支凭证或存在企业营销账户余额表中)
  243. Rows rowscashbill = dbConnect.runSqlQuery("select sa_cashbillid from sa_cashbill where sa_accountclassid="
  244. + sa_accountclassid + " and status='审核'");
  245. Rows rowsaccountbalance = dbConnect.runSqlQuery(
  246. "select sa_accountbalanceid from sa_accountbalance where sa_accountclassid=" + sa_accountclassid);
  247. if (!rowscashbill.isEmpty() || !rowsaccountbalance.isEmpty()) {
  248. batchDeleteErr.addErr(sa_accountclassid, "此营销账户类型已被使用,无法删除");
  249. continue;
  250. }
  251. }
  252. ArrayList<String> list = new ArrayList<>();
  253. SQLFactory deletesql = new SQLFactory("sql:delete from sa_accountclass where siteid='" + siteid
  254. + "' and sa_accountclassid=" + sa_accountclassid);
  255. list.add(deletesql.getSQL());
  256. dbConnect.runSqlUpdate(list);
  257. }
  258. return batchDeleteErr.getReturnObject().toString();
  259. }
  260. }