懒羊羊
2023-08-30 71e81ed1d12e4d69f53c8ad9e066650ad4186293
提交 | 用户 | 时间
71e81e 1 /**
2  * Copyright 2018-2020 stylefeng & fengshuonan (https://gitee.com/stylefeng)
3  * <p>
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  * <p>
8  * http://www.apache.org/licenses/LICENSE-2.0
9  * <p>
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package cn.stylefeng.guns.sys.modular.system.warpper;
17
18 import cn.stylefeng.guns.base.db.util.ClobUtil;
19 import cn.stylefeng.guns.sys.core.constant.factory.ConstantFactory;
20 import cn.stylefeng.guns.sys.core.util.Contrast;
21 import cn.stylefeng.guns.sys.core.util.DecimalUtil;
22 import cn.stylefeng.roses.core.base.warpper.BaseControllerWrapper;
23 import cn.stylefeng.roses.core.util.ToolUtil;
24 import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
25
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30  * 日志列表的包装类
31  *
32  * @author fengshuonan
33  * @date 2017年4月5日22:56:24
34  */
35 public class LogWrapper extends BaseControllerWrapper {
36
37     public LogWrapper(Map<String, Object> single) {
38         super(single);
39     }
40
41     public LogWrapper(List<Map<String, Object>> multi) {
42         super(multi);
43     }
44
45     @Override
46     protected void wrapTheMap(Map<String, Object> map) {
47
48         String message = "";
49
50         Object messageObj = map.get("message");
51         if (messageObj instanceof ClobProxyImpl) {
52             ClobProxyImpl clobProxy = (ClobProxyImpl) messageObj;
53             message = ClobUtil.clobToString(clobProxy.getRawClob());
54         } else {
55             message = (String) messageObj;
56         }
57
58         Long userid = DecimalUtil.getLong(map.get("userId"));
59         map.put("userName", ConstantFactory.me().getUserNameById(userid));
60
61         //如果信息过长,则只截取前100位字符串
62         if (ToolUtil.isNotEmpty(message) && message.length() >= 100) {
63             String subMessage = message.substring(0, 100) + "...";
64             map.put("message", subMessage);
65         }
66
67         //如果信息中包含分割符号;;;   则分割字符串返给前台
68         if (ToolUtil.isNotEmpty(message) && message.contains(Contrast.separator)) {
69             String[] msgs = message.split(Contrast.separator);
70             map.put("regularMessage", msgs);
71         } else {
72             map.put("regularMessage", message);
73         }
74     }
75 }