22
33import java .sql .ResultSet ;
44import java .sql .SQLException ;
5+ import java .text .DateFormat ;
6+ import java .text .ParseException ;
7+ import java .text .SimpleDateFormat ;
58import java .util .ArrayList ;
69import java .util .LinkedHashMap ;
710import java .util .LinkedList ;
@@ -84,21 +87,28 @@ public PaginatorResult getPaginatorList(Paginator paginator, QueryCommBean bean)
8487
8588 Map <String , String > dicts = dictService .getByTypeMaps ("_file_types" );
8689 Map <String , String > servers_type = dictService .getByTypeMaps ("servers_type" );
90+
91+ // 技能列表
92+ Map <String , String > zl_skill_type = gameDictService .getByTypeMaps ("zl_skill_type" );
93+ // 监听列表
94+ Map <String , Dict > zl_event_type = gameDictService .getByTypeMapsDicts ("zl_event_type" );
95+ // 效果概率
96+ Map <String , String > zl_effect_type = gameDictService .getByTypeMaps ("zl_effect_type" );
97+ // BUFF
98+ Map <String , Dict > zl_buff_types = gameDictService .getByTypeMapsDicts ("zl_buff_types" );
99+
100+ // 属性
101+ Map <String , Dict > zl_attrs_types = gameDictService .getByTypeMapsDicts ("zl_attrs_types" );
102+
87103
88- //技能列表
89- Map <String ,String > zl_skill_type = gameDictService .getByTypeMaps ("zl_skill_type" );
90- //监听列表
91- Map <String ,Dict > zl_event_type = gameDictService .getByTypeMapsDicts ("zl_event_type" );
92- //效果概率
93- Map <String ,String > zl_effect_type = gameDictService .getByTypeMaps ("zl_effect_type" );
94- //BUFF
95- Map <String ,Dict > zl_buff_types = gameDictService .getByTypeMapsDicts ("zl_buff_types" );
96-
104+ //去掉空的。主要是属性对比
105+ // List<CombatLog> data_new = new LinkedList<CombatLog>();
106+ System .out .println (JSONObject .toJSONString (data ));
97107 // 转换中文
98108 if (data != null && data .size () > 0 ) {
99109 for (CombatLog log : data ) {
100- //有些需要做判单
101- // log.setFileSrc(log.getFile());
110+ // 有些需要做判单
111+ // log.setFileSrc(log.getFile());
102112 // 转换文件名
103113 if (dicts .containsKey (log .getFile ())) {
104114 log .setFileName (dicts .get (log .getFile ()));
@@ -109,37 +119,37 @@ public PaginatorResult getPaginatorList(Paginator paginator, QueryCommBean bean)
109119 } else {
110120 log .setServer (String .valueOf (log .getServerId ()));
111121 }
112- //技能名转换
113- if (StringUtils .isBlank (log .getCont ())){
122+ // 技能名转换
123+ if (StringUtils .isBlank (log .getCont ())) {
114124 continue ;
115125 }
116- if ("skill" .equals (log .getFile ())){
117- JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
118- if (!jsonCont .containsKey ("skill_id" )|| StringUtils .isBlank (jsonCont .getString ("skill_id" ))){
126+ if ("skill" .equals (log .getFile ())) {
127+ JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
128+ if (!jsonCont .containsKey ("skill_id" ) || StringUtils .isBlank (jsonCont .getString ("skill_id" ))) {
119129 continue ;
120130 }
121- String skill_id = jsonCont .getString ("skill_id" );
122- String skill_name = zl_skill_type .get (skill_id );
131+ String skill_id = jsonCont .getString ("skill_id" );
132+ String skill_name = zl_skill_type .get (skill_id );
123133 jsonCont .put ("skill_name" , skill_name );
124134 log .setCont (jsonCont .toJSONString ());
125135 }
126- //监听转换
127- if ("opport" .equals (log .getFile ())){
128- JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
129- if (!jsonCont .containsKey ("opports" )|| StringUtils .isBlank (jsonCont .getString ("opports" ))){
136+ // 监听转换
137+ if ("opport" .equals (log .getFile ())) {
138+ JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
139+ if (!jsonCont .containsKey ("opports" ) || StringUtils .isBlank (jsonCont .getString ("opports" ))) {
130140 continue ;
131141 }
132- String key = jsonCont .getString ("opports" );//是一个数组,需转换
133- String arrs_str = key .replace ("[" , "" ).replace ("]" , "" );
134- String [] arrs = arrs_str .split ("," );
135- if (arrs != null && arrs .length > 0 ) {
136- List <Dict > d_temp = new ArrayList <>();
137- for (String arr_key : arrs ){
138- if (zl_event_type .containsKey (arr_key )){
139- Dict dict = zl_event_type .get (arr_key );
142+ String key = jsonCont .getString ("opports" );// 是一个数组,需转换
143+ String arrs_str = key .replace ("[" , "" ).replace ("]" , "" );
144+ String [] arrs = arrs_str .split ("," );
145+ if (arrs != null && arrs .length > 0 ) {
146+ List <Dict > d_temp = new ArrayList <>();
147+ for (String arr_key : arrs ) {
148+ if (zl_event_type .containsKey (arr_key )) {
149+ Dict dict = zl_event_type .get (arr_key );
140150 d_temp .add (dict );
141- }else {//没有找到,则显示为id
142- Dict dict = new Dict ();
151+ } else {// 没有找到,则显示为id
152+ Dict dict = new Dict ();
143153 dict .setValue (arr_key );
144154 dict .setName (arr_key );
145155 dict .setRemake (arr_key );
@@ -149,52 +159,53 @@ public PaginatorResult getPaginatorList(Paginator paginator, QueryCommBean bean)
149159 }
150160 log .setCont (jsonCont .toJSONString ());
151161 }
152- //效果转换
153- if ("effect" .equals (log .getFile ())){
154- JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
155- if (!jsonCont .containsKey ("effect_id" )|| StringUtils .isBlank (jsonCont .getString ("effect_id" ))){
162+ // 效果转换
163+ if ("effect" .equals (log .getFile ())) {
164+ JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
165+ if (!jsonCont .containsKey ("effect_id" ) || StringUtils .isBlank (jsonCont .getString ("effect_id" ))) {
156166 continue ;
157167 }
158- String key = jsonCont .getString ("effect_id" );
159- if (zl_effect_type .containsKey (key )){
160- String skill_name = zl_effect_type .get (key );
168+ String key = jsonCont .getString ("effect_id" );
169+ if (zl_effect_type .containsKey (key )) {
170+ String skill_name = zl_effect_type .get (key );
161171 jsonCont .put ("effect_Prob" , skill_name );
162- }else {
172+ } else {
163173 jsonCont .put ("effect_Prob" , key );
164174 }
165175 log .setCont (jsonCont .toJSONString ());
166176 }
167-
168- //BUFF处理效果 把file转换 add_buf 添加Buf del_buf 删除Buf buf_expire Buf过期删除
169- if ("add_buf" .equals (log .getFile ())||"del_buf" .equals (log .getFile ())||"buf_expire" .equals (log .getFile ())){
177+ // BUFF处理效果 把file转换 add_buf 添加Buf del_buf 删除Buf buf_expire
178+ // Buf过期删除
179+ if ("add_buf" .equals (log .getFile ()) || "del_buf" .equals (log .getFile ())
180+ || "buf_expire" .equals (log .getFile ())) {
170181 log .setFileName ("BUFF处理效果" );
171- // log.setFile("buff_all");
172- //查询buffstatus
173- JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
174- // if(!jsonCont.containsKey("add_bufs")||StringUtils.isBlank(jsonCont.getString("add_bufs"))){
175- // continue;
176- // }
177- String key = "" ;
178-
179- if (jsonCont .containsKey ("add_bufs" )){
180- key = jsonCont .getString ("add_bufs" );//是一个数组,需转换
182+ // log.setFile("buff_all");
183+ // 查询buffstatus
184+ JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
185+ // if(!jsonCont.containsKey("add_bufs")||StringUtils.isBlank(jsonCont.getString("add_bufs"))){
186+ // continue;
187+ // }
188+ String key = "" ;
189+
190+ if (jsonCont .containsKey ("add_bufs" )) {
191+ key = jsonCont .getString ("add_bufs" );// 是一个数组,需转换
181192 }
182- if (jsonCont .containsKey ("del_buff_ids" )){
183- key = jsonCont .getString ("del_buff_ids" );//是一个数组,需转换
193+ if (jsonCont .containsKey ("del_buff_ids" )) {
194+ key = jsonCont .getString ("del_buff_ids" );// 是一个数组,需转换
184195 }
185- if (jsonCont .containsKey ("del_buff_ids" )){
186- key = jsonCont .getString ("del_buff_ids" );//是一个数组,需转换
196+ if (jsonCont .containsKey ("del_buff_ids" )) {
197+ key = jsonCont .getString ("del_buff_ids" );// 是一个数组,需转换
187198 }
188- String arrs_str = key .replace ("[" , "" ).replace ("]" , "" );
189- String [] arrs = arrs_str .split ("," );
190- if (arrs != null && arrs .length > 0 ) {
191- List <Dict > d_temp = new ArrayList <>();
192- for (String arr_key : arrs ){
193- if (zl_buff_types .containsKey (arr_key )){
194- Dict dict = zl_buff_types .get (arr_key );
199+ String arrs_str = key .replace ("[" , "" ).replace ("]" , "" );
200+ String [] arrs = arrs_str .split ("," );
201+ if (arrs != null && arrs .length > 0 ) {
202+ List <Dict > d_temp = new ArrayList <>();
203+ for (String arr_key : arrs ) {
204+ if (zl_buff_types .containsKey (arr_key )) {
205+ Dict dict = zl_buff_types .get (arr_key );
195206 d_temp .add (dict );
196- }else {//没有找到,则显示为id
197- Dict dict = new Dict ();
207+ } else {// 没有找到,则显示为id
208+ Dict dict = new Dict ();
198209 dict .setValue (arr_key );
199210 dict .setName (arr_key );
200211 dict .setRemake (arr_key );
@@ -203,18 +214,123 @@ public PaginatorResult getPaginatorList(Paginator paginator, QueryCommBean bean)
203214 jsonCont .put ("buff_all_json" , d_temp );
204215 }
205216 log .setCont (jsonCont .toJSONString ());
206-
207217 }
208-
209-
210-
218+ // 属性变更 最当前的一条和,最近的一条比较
219+ if ("attrs" .equals (log .getFile ())) {
220+ JSONObject jsonCont = (JSONObject ) JSONObject .parse (log .getCont ());
221+ if (!jsonCont .containsKey ("uuid" ) || StringUtils .isBlank (jsonCont .getString ("uuid" ))) {
222+ log .setCont ("" );
223+ continue ;
224+ }
225+ try {
226+ log = diffAttrs (log , zl_attrs_types );
227+ } catch (ParseException e ) {
228+ e .printStackTrace ();
229+ continue ;
230+ }
231+ // log.setCont(jsonCont.toJSONString());
232+ }
233+
211234 }
235+
236+ // for (CombatLog log : data) {
237+ // if(StringUtils.isNotBlank(log.getCont())){
238+ // data_new.add(log);
239+ // }
240+ // }
212241 }
213242
214243 result .setRows (data );
215244 return result ;
216245 }
217246
247+ /**
248+ * 比较属性变化,并显示
249+ *
250+ * @param src
251+ * @return
252+ * @throws ParseException
253+ */
254+ public CombatLog diffAttrs (CombatLog log_src , Map <String , Dict > zl_attrs_types ) throws ParseException {
255+
256+ if (zl_attrs_types == null || zl_attrs_types .size () <= 0 ) {
257+ log_src .setCont ("{\" msg\" :\" 字典为空\" }" );
258+ return log_src ;
259+ }
260+
261+ String uuid = log_src .getUuid ();
262+ String dt = log_src .getDt ();
263+
264+ String diff_dt = "" ;
265+ if (StringUtils .isNotBlank (dt )) {
266+ DateFormat df = (DateFormat ) new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss" );
267+ long d_long = df .parse (dt ).getTime () - 120000 ;// 二分钟类的日志
268+ diff_dt = df .format (d_long );
269+ }
270+ if (StringUtils .isBlank (diff_dt )) {
271+ log_src .setCont ("" );
272+ return log_src ;
273+ }
274+ StringBuffer sql = new StringBuffer ();
275+ sql .append (
276+ "SELECT id,server_id,file,to_char(time,'YYYY-MM-DD HH24:MI:SS') dt,cont->>'uuid' uuid,cont cont FROM zl_log_info where file='attrs' " );
277+ sql .append (" and cont->>'uuid'='" );
278+ sql .append (uuid );
279+ sql .append ("'" );
280+ // 取二分钟内的
281+ sql .append (" and time<'" );
282+ sql .append (dt );
283+ sql .append ("'" );
284+
285+ sql .append (" and time>'" );
286+ sql .append (diff_dt );
287+ sql .append ("'" );
288+ sql .append (" order by id desc limit 1" );
289+ log .info ("sql:>>>\n {}\n " , sql .toString ());
290+
291+ CombatLog datax = gdataDao .selectObject (sql .toString (), rowMapper2 );
292+ if (datax == null ) {
293+ log_src .setCont ("{\" msg\" :\" 末能找到下一条做比较\" }" );
294+ return log_src ;
295+
296+ }
297+
298+ JSONObject jsonCont_dif = (JSONObject ) JSONObject .parse (datax .getCont ());
299+ JSONObject jsonCont_src = (JSONObject ) JSONObject .parse (log_src .getCont ());
300+ // 比较
301+ JSONObject cont = new JSONObject ();
302+
303+
304+ for (Entry <String , Dict > entry : zl_attrs_types .entrySet ()) {
305+ String dif = jsonCont_dif .getString (entry .getKey ());
306+ String src = jsonCont_src .getString (entry .getKey ());
307+
308+ if (StringUtils .isBlank (src )) {
309+ continue ;
310+ }
311+ if (StringUtils .isBlank (dif )) {
312+ cont .put (entry .getValue ().getName (), "当前值:" + src + "|变更前值:空" );
313+ } else if (!dif .equals (src )) {
314+ cont .put (entry .getValue ().getName (), "当前值:" + src + "|变更前值:" + dif );
315+ }
316+ }
317+
318+
319+
320+
321+ if (StringUtils .isBlank (cont .toJSONString ())||"{}" .equals (cont .toJSONString ())) {
322+ // conts="{\"msg\":\"无变化\"}";
323+ cont .put ("msg" , "无变化" );
324+ }
325+ //必要信息
326+ cont .put ("file" , log_src .getFile ());
327+ JSONObject contJSON =(JSONObject ) JSONObject .parse (log_src .getCont ());
328+ cont .put ("name" , contJSON .getString ("name" ));
329+
330+ log_src .setCont (cont .toJSONString ());
331+ return log_src ;
332+ }
333+
218334 private RowMapper <CombatLog > rowMapper = new RowMapper <CombatLog >() {
219335 @ Override
220336 public CombatLog mapRow (ResultSet rs , int rowNum ) throws SQLException {
@@ -229,6 +345,20 @@ public CombatLog mapRow(ResultSet rs, int rowNum) throws SQLException {
229345 }
230346 };
231347
348+ private RowMapper <CombatLog > rowMapper2 = new RowMapper <CombatLog >() {
349+ @ Override
350+ public CombatLog mapRow (ResultSet rs , int rowNum ) throws SQLException {
351+ CombatLog bean = new CombatLog ();
352+ bean .setId (rs .getLong ("id" ));
353+ bean .setServerId (rs .getInt ("server_id" ));
354+ bean .setDt (rs .getString ("dt" ));
355+ bean .setUuid (rs .getString ("uuid" ));
356+ bean .setFile (rs .getString ("file" ));
357+ bean .setCont (rs .getString ("cont" ));
358+ return bean ;
359+ }
360+ };
361+
232362 /**
233363 * 获取总记录数
234364 *
@@ -377,7 +507,7 @@ public Dict mapRow(ResultSet rs, int rowNum) throws SQLException {
377507 bean .setValue (rs .getString ("uuid" ));
378508 // actor_type 角色类型(human=玩家, mon=怪物, partner=人物的招唤物)
379509 String type = rs .getString ("actory" );
380- String name = rs .getString ("namea" );
510+ String name = rs .getString ("namea" );
381511 if (StringUtils .isBlank (type )) {
382512 type = "" ;
383513 }
@@ -449,21 +579,24 @@ public CombatAttr getAttrs(QueryCommBean bean) {
449579 sql .append (" LIMIT 1" );
450580 log .info ("sql:>>>\n {}\n param={}" , sql .toString (), paramArray .toArray ());
451581 CombatAttr data = gdataDao .selectObject (sql .toString (), rowMapper_attrs );
452-
453- //取下一条
454- // select * from zl_log_info where file='attrs' and cont->>'uuid'='10000114' and time<'2017-06-29 17:32:13' order by time desc LIMIT 1
455- CombatAttr dif =getDifAttrs (bean ,maxDate );
456- if (dif !=null &&StringUtils .isNotBlank (dif .getCont ())){
457- //对比数据
582+
583+ // 取下一条
584+ // select * from zl_log_info where file='attrs' and
585+ // cont->>'uuid'='10000114' and time<'2017-06-29 17:32:13' order by time
586+ // desc LIMIT 1
587+ CombatAttr dif = getDifAttrs (bean , maxDate );
588+ if (dif != null && StringUtils .isNotBlank (dif .getCont ())) {
589+ // 对比数据
458590 data .setContDif (dif .getCont ());
459591 }
460592 data .setTime (maxDate );
461593 return data ;
462594 }
463-
464- //取下一条
465- // select * from zl_log_info where file='attrs' and cont->>'uuid'='10000114' and time<'2017-06-29 17:32:13' order by time desc LIMIT 1
466- public CombatAttr getDifAttrs (QueryCommBean bean ,String time ) {
595+
596+ // 取下一条
597+ // select * from zl_log_info where file='attrs' and cont->>'uuid'='10000114'
598+ // and time<'2017-06-29 17:32:13' order by time desc LIMIT 1
599+ public CombatAttr getDifAttrs (QueryCommBean bean , String time ) {
467600 bean .setFile ("attrs" );
468601 // 获取最大的时间
469602 String maxDate = getMaxTime (bean );
@@ -487,7 +620,6 @@ public CombatAttr getDifAttrs(QueryCommBean bean,String time) {
487620 data .setTime (maxDate );
488621 return data ;
489622 }
490-
491623
492624 private RowMapper <CombatAttr > rowMapper_attrs = new RowMapper <CombatAttr >() {
493625 @ Override
0 commit comments