accountclass.java 15 KB

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