TableServiceContext.java 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package com.boman.system.common;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.boman.common.core.utils.SpringUtils;
  4. import com.boman.common.redis.RedisKey;
  5. import com.boman.common.redis.service.RedisService;
  6. import com.boman.gen.domain.GenTable;
  7. import com.google.common.base.Strings;
  8. import com.google.common.collect.Lists;
  9. import com.google.common.collect.Maps;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.util.StringUtils;
  12. import javax.annotation.Resource;
  13. import java.sql.Timestamp;
  14. import java.util.*;
  15. /**
  16. * @author shiqian
  17. * @description
  18. * @date 2021年03月22日 09:58
  19. **/
  20. @Service
  21. public class TableServiceContext {
  22. private final static String PREFIX = "Controller:/event/do";
  23. /**
  24. * 当前表
  25. */
  26. private GenTable table;
  27. /**
  28. * 真实表名
  29. */
  30. private String realTableName;
  31. /**
  32. * 动作名(ADD,SAVE,SUBMIT,VOID,UNSUBMIT)
  33. */
  34. private String actionName; //Controller:/event/doAdd
  35. /**
  36. * 业务发生的时间戳
  37. */
  38. private Timestamp currentTime;
  39. /**
  40. * 上行的数据
  41. * 每个row对象对应到一条单据(如果存在事务,应该在这个级别上体现)
  42. */
  43. private List<MainTableRecord> rows;
  44. /**
  45. * 本次请求存放的临时数据
  46. * !!慎用,最好不要在各个对象间传递
  47. */
  48. private Map<String, Object> values;
  49. private boolean isDelMtable;
  50. /**
  51. * 是否批量新增
  52. */
  53. private boolean isInsertBacth = false;
  54. private TableServiceContext() {
  55. values = Maps.newHashMap();
  56. }
  57. @Resource
  58. private RedisService redisService;
  59. public static TableServiceContext createFrom(BaseTableDTO baseTableDTO) {
  60. TableServiceContext result = new TableServiceContext();
  61. String tableName = baseTableDTO.getTable();
  62. if (StringUtils.isEmpty(tableName)) {
  63. throw new IllegalArgumentException("表名参数不能为空");
  64. }
  65. //从redis中获取表信息
  66. RedisService redisService = SpringUtils.getBean(RedisService.class);
  67. result.table = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
  68. if (result.table == null) {
  69. throw new IllegalArgumentException(tableName + "表信息不存在");
  70. }
  71. result.realTableName = result.table.getTableName();
  72. if (Strings.isNullOrEmpty(result.realTableName)) {
  73. throw new IllegalArgumentException(tableName + "表名不存在");
  74. }
  75. // 前台传过来的数据
  76. JSONObject fixedData = baseTableDTO.getFixedData();
  77. //删除
  78. Boolean isdelmtable = baseTableDTO.getDelMTable();
  79. JSONObject tabItem = baseTableDTO.getTabItem();
  80. if (isdelmtable != null) {
  81. result.isDelMtable = isdelmtable;
  82. }
  83. result.currentTime = new Timestamp(System.currentTimeMillis());
  84. // 获取objid判断 新增或更新
  85. Long objid = baseTableDTO.getObjId();
  86. MainTableRecord mainRowData = new MainTableRecord(result, result.table, objid, fixedData, tabItem);
  87. result.rows = Lists.newArrayList();
  88. result.rows.add(mainRowData);
  89. return result;
  90. }
  91. public GenTable getTable() {
  92. return table;
  93. }
  94. public void setTable(GenTable table) {
  95. this.table = table;
  96. }
  97. public String getRealTableName() {
  98. return realTableName;
  99. }
  100. public void setRealTableName(String realTableName) {
  101. this.realTableName = realTableName;
  102. }
  103. public String getActionName() {
  104. return actionName;
  105. }
  106. public void setActionName(String actionName) {
  107. this.actionName = actionName;
  108. }
  109. public Timestamp getCurrentTime() {
  110. return currentTime;
  111. }
  112. public void setCurrentTime(Timestamp currentTime) {
  113. this.currentTime = currentTime;
  114. }
  115. public List<MainTableRecord> getRows() {
  116. return rows;
  117. }
  118. public void setRows(List<MainTableRecord> rows) {
  119. this.rows = rows;
  120. }
  121. public Map<String, Object> getValues() {
  122. return values;
  123. }
  124. public void setValues(Map<String, Object> values) {
  125. this.values = values;
  126. }
  127. public boolean isDelMtable() {
  128. return isDelMtable;
  129. }
  130. public void setDelMtable(boolean delMtable) {
  131. isDelMtable = delMtable;
  132. }
  133. public boolean isInsertBacth() {
  134. return isInsertBacth;
  135. }
  136. public void setInsertBacth(boolean insertBacth) {
  137. isInsertBacth = insertBacth;
  138. }
  139. //
  140. // public Collection<Filter> getFilters() {
  141. // return filters;
  142. // }
  143. //
  144. // public void setFilters(Collection<Filter> filters) {
  145. // this.filters = filters;
  146. // }
  147. }