accountclass.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. @CACHEING
  131. public String queryAccountclass() throws YosException {
  132. /*
  133. * 过滤条件设置
  134. */
  135. String where = " 1=1 ";
  136. if (content.containsKey("where")) {
  137. JSONObject whereObject = content.getJSONObject("where");
  138. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  139. where = where + " and(accountname like'%" + whereObject.getString("condition")
  140. + "%' or accountno like '%" + whereObject.getString("condition") + "%')";
  141. }
  142. if (whereObject.containsKey("isused") && !"".equals(whereObject.getString("isused"))) {
  143. where = where + " and t1.isused=" + whereObject.getLong("isused");
  144. }
  145. if (whereObject.containsKey("isorder") && !"".equals(whereObject.getString("isorder"))) {
  146. where = where + " and t1.isorder=" + whereObject.getLong("isorder");
  147. }
  148. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  149. where = where + " and t1.isrebate=" + whereObject.getLong("isrebate");
  150. }
  151. if (whereObject.containsKey("isnotspecialfund") && !"".equals(whereObject.getString("isnotspecialfund"))) {
  152. where = where + " and (JSON_TYPE(t1.bindingcategories) = 'NULL' || JSON_LENGTH(t1.bindingcategories) = 0) and t1.accountname !='保证金账户' ";
  153. }
  154. }
  155. if(content.containsKey("sys_enterpriseid")){
  156. sys_enterpriseid=content.getLongValue("sys_enterpriseid");
  157. }
  158. /*
  159. * SQL通告板块查询参数设置并查询
  160. */
  161. SQLFactory factory = new SQLFactory(this, "营销账户类型列表查询");
  162. factory.addParameter("siteid", siteid);
  163. factory.addParameter("sys_enterpriseid", sys_enterpriseid);
  164. factory.addParameter_SQL("where", where);
  165. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  166. // for (Row row:rows) {
  167. // JSONArray bindingcategories= row.getJSONArray("bindingcategories");
  168. // if(bindingcategories.size()>0){
  169. // Rows itemclassRows = dbConnect.runSqlQuery("select * from plm_itemclass where siteid='"+siteid+"' and classtype='营销' and itemclassid in"+bindingcategories.toJSONString().replace("[", "(").replace("]", ")"));
  170. // row.put("bindingcategories",itemclassRows.toJsonArray("itemclassname"));
  171. // }else{
  172. // row.put("bindingcategories",new JSONArray());
  173. // }
  174. // }
  175. return getSucReturnObject().setData(rows).toString();
  176. }
  177. /**
  178. * 查询营销账户余额
  179. *
  180. * @return
  181. */
  182. @API(title = "查询营销账户余额", apiversion = R.ID20221008145903.v1.class)
  183. @CACHEING
  184. public String queryAccountbalance() throws YosException {
  185. long type = content.getLongValue("type");
  186. /*
  187. 过滤条件设置
  188. */
  189. String where = " 1=1 ";
  190. if (content.containsKey("where")) {
  191. JSONObject whereObject = content.getJSONObject("where");
  192. if (whereObject.containsKey("sys_enterpriseid") && !"".equals(whereObject.getString("sys_enterpriseid"))) {
  193. where = where + " and t1.sys_enterpriseid='" + whereObject.getString("sys_enterpriseid") + "' ";
  194. }
  195. if (whereObject.containsKey("enterprisename") && !"".equals(whereObject.getString("enterprisename"))) {
  196. where = where + " and t3.enterprisename='" + whereObject.getString("enterprisename") + "' ";
  197. }
  198. if (whereObject.containsKey("accountno") && !"".equals(whereObject.getString("accountno"))) {
  199. where = where + " and t2.accountno='" + whereObject.getString("accountno") + "' ";
  200. }
  201. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  202. where = where + " and t2.accountname='" + whereObject.getString("accountname") + "' ";
  203. }
  204. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  205. where = where + " and (t2.accountname like'%" + whereObject.getString("condition") + "%' " +
  206. "or t3.enterprisename like'%" + whereObject.getString("condition") + "%' " +
  207. "or t4.agentnum like'%" + whereObject.getString("condition") + "%' " +
  208. ") ";
  209. }
  210. }
  211. if (type == 1) {
  212. where = where + " and t1.sys_enterpriseid='" + sys_enterpriseid + "' ";
  213. }
  214. /*
  215. * SQL通告板块查询参数设置并查询
  216. */
  217. SQLFactory factory = new SQLFactory(this, "营销账户余额查询", pageSize, pageNumber, pageSorting);
  218. factory.addParameter("siteid", siteid);
  219. factory.addParameter_SQL("where", where);
  220. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  221. if (!rows.isEmpty()) {
  222. for (Row row : rows) {
  223. row.put("balance", row.getBigDecimal("balance"));
  224. row.put("creditquota", row.getBigDecimal("creditquota"));
  225. }
  226. }
  227. return getSucReturnObject().setData(rows).toString();
  228. }
  229. @API(title = "删除", apiversion = R.ID20221008134903.v1.class)
  230. @CACHEING_CLEAN(cms = {@cm(clazz = accountclass.class, method = {"queryAccountclass"}), @cm(clazz = creditbill.class, method = {"queryAccountclassList"})})
  231. public String delete() throws YosException {
  232. JSONArray sa_accountclassids = content.getJSONArray("sa_accountclassids");
  233. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_accountclassids.size());
  234. for (Object o : sa_accountclassids) {
  235. long sa_accountclassid = Long.parseLong(o.toString());
  236. Rows RowsStatus = dbConnect.runSqlQuery("select sa_accountclassid,isused from sa_accountclass where siteid='"
  237. + siteid + "' and sa_accountclassid='" + sa_accountclassid + "'");
  238. if (RowsStatus.isNotEmpty()) {
  239. if (RowsStatus.get(0).getBoolean("isused")) {
  240. batchDeleteErr.addErr(sa_accountclassid, "此营销账户类型已启用,无法删除");
  241. continue;
  242. }
  243. // 判断账户类型是否被使用(存在收支凭证或存在企业营销账户余额表中)
  244. Rows rowscashbill = dbConnect.runSqlQuery("select sa_cashbillid from sa_cashbill where sa_accountclassid="
  245. + sa_accountclassid + " and status='审核'");
  246. Rows rowsaccountbalance = dbConnect.runSqlQuery(
  247. "select sa_accountbalanceid from sa_accountbalance where sa_accountclassid=" + sa_accountclassid);
  248. if (!rowscashbill.isEmpty() || !rowsaccountbalance.isEmpty()) {
  249. batchDeleteErr.addErr(sa_accountclassid, "此营销账户类型已被使用,无法删除");
  250. continue;
  251. }
  252. }
  253. ArrayList<String> list = new ArrayList<>();
  254. SQLFactory deletesql = new SQLFactory("sql:delete from sa_accountclass where siteid='" + siteid
  255. + "' and sa_accountclassid=" + sa_accountclassid);
  256. list.add(deletesql.getSQL());
  257. dbConnect.runSqlUpdate(list);
  258. }
  259. return batchDeleteErr.getReturnObject().toString();
  260. }
  261. }