xinyb
2022-11-14 ec748c832461adedf864d7bb6edd4ee89463abb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package com.yc.action.upload;
 
import com.yc.entity.attachment.AttachmentOAParam;
import com.yc.entity.attachment.AttachmentOaEntity;
import com.yc.multiData.SpObserver;
import com.yc.phoneQRLogin.utils.BackMsg;
import com.yc.service.impl.DBHelper;
import com.yc.service.upload.AttachmentOaIfc;
import com.yc.utils.SessionKey;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Array;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
 
/**
 * @Author xinyb
 * @Date 14:43 2022/11/1
 **/
@RestController
@RequestMapping("/attachmentOa")
public class AttachmentOA {
 
    @Autowired
    AttachmentOaIfc attachmentOaIfc;
 
    @RequestMapping(value = "/userInfo.do", method = RequestMethod.GET)
    public BackMsg getAttachmentOAUserInfo(String unid, Integer seq, String keyword, HttpServletRequest request, HttpServletResponse response) {
        BackMsg msg = new BackMsg();
        try {
            if (StringUtils.isBlank(unid)) {
                msg.setFail("附件控件唯一unid不能为空");
                return msg;
            }
            if (seq == null || seq == 0) {
                msg.setFail("附件标识seq不能为空");
                return msg;
            }
            String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance("_" + dbId);
            List<Map<String, Object>> list = attachmentOaIfc.getAttachmentOAUserInfo(unid, seq, keyword);
            if (list != null && list.size() > 0) {
                msg.setOk(Configure(list));
            } else {
                if (StringUtils.isNotBlank(keyword)) {
                    msg.setOk(list);
                    return msg;
                }
                msg.setFail("获取不到用户信息");
            }
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    @RequestMapping("/setUserOA.do")
    public BackMsg setAttachmentOAUser(@RequestBody AttachmentOAParam param, HttpServletRequest request, HttpServletResponse response) {
        BackMsg msg = new BackMsg();
        try {
            if (param == null || StringUtils.isBlank(param.getUnid())) {
                msg.setFail("参数错误");
                return msg;
            }
            String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance("_" + dbId);
            Integer cont = attachmentOaIfc.setAttachmentOAUser(param);
            msg.setOk("设置成功");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
 
    }
 
    @RequestMapping("/getOAInfo.do")
    public BackMsg getAttachmentOAInfo(@RequestBody AttachmentOAParam param, HttpServletRequest request) {
        BackMsg msg = new BackMsg();
        try {
            if (StringUtils.isBlank(param.getUnid()) || param.getSeq() == null || param.getSeq() == 0) {
                msg.setFail("附件的参数信息不能为空");
                return msg;
            }
            if (StringUtils.isBlank(param.getUserCode())) {
                param.setUserCode((String) request.getSession().getAttribute(SessionKey.HRCODE));
            }
            String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance("_" + dbId);
            Map<String, Object> info = attachmentOaIfc.getAttachmentOAInfo(param);
            if (info == null) {
                msg.setFail("无法找到附件内容,检查附件参数是否正确");
                return msg;
            }
            msg.setOk(info);
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    @RequestMapping("/getAllowOa.do")
    public BackMsg getAttachmentAllow(@RequestBody AttachmentOAParam param, HttpServletRequest request) {
        BackMsg msg = new BackMsg();
        try {
            if (StringUtils.isBlank(param.getUnid()) || param.getSeq() == null || param.getSeq() == 0) {
                msg.setFail("附件的参数信息不能为空");
                return msg;
            }
            if (StringUtils.isBlank(param.getUserCode())) {
                param.setUserCode((String) request.getSession().getAttribute(SessionKey.HRCODE));
            }
            String dbId = (String) request.getSession().getAttribute(SessionKey.DATA_BASE_ID);
            SpObserver.setDBtoInstance("_" + dbId);
            String memo = attachmentOaIfc.getAttachmentAllow(param);
            if (StringUtils.isBlank(memo)) {
                msg.setFail("获取不到附件更新内容");
                return msg;
            }
            String[] info = memo.split(";");
            if (info.length == 9) {
                Map<String, Object> map = new HashMap<>();
                map.put("allowViewNums", info[0]);
                map.put("viewNums",info[1]);
                map.put("allowDownNums",info[2]);
                map.put("downNums",info[3]);
                map.put("type", info[4]);
                map.put("state", info[5]);
                map.put("describe", info[6]);
                map.put("totaViewNums", info[7]);
                map.put("totaDownNums", info[8]);
                msg.setOk(map);
            }
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 配置用户结构
     *
     * @param list
     * @return
     */
    private List<Map<String, Object>> Configure(List<Map<String, Object>> list) {
        List<Map<String, Object>> out = new ArrayList<>();
        try {
            String filedId = "ccCode";
            for (Map<String, Object> m : list) {
                String value = DBHelper.getValue(m, filedId).toLowerCase();
                if (out.stream().filter(o -> value.equals(o.get(filedId) != null ? o.get(filedId).toString().toLowerCase() : "")).count() == 0) {//等于0表示还没有组装到value值
                    //获取相同value的集合
                    List<Map<String, Object>> similar = list.stream().filter(l -> value.equals(DBHelper.getValue(l, filedId).toLowerCase())).collect(Collectors.toList());
                    //创建一个新map存放相同value
                    Map<String, Object> map = new HashMap<>();
                    map.put(filedId, DBHelper.getValue(m, filedId));
                    map.put("ccName", DBHelper.getValue(m, "ccName"));
                    List<AttachmentOaEntity> oaEntities = new ArrayList<>();
                    boolean check = true;//假设全部选中
                    SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
                    for (Map<String, Object> map1 : similar) {
                        AttachmentOaEntity oaEntity = new AttachmentOaEntity();
                        oaEntity.setCcCode(DBHelper.getValue(map1, filedId));
                        oaEntity.setCcName(DBHelper.getValue(map1, "ccName"));
                        oaEntity.setUserCode(DBHelper.getValue(map1, "userCode"));
                        oaEntity.setUserName(DBHelper.getValue(map1, "userName"));
                        oaEntity.setHasView(DBHelper.getValueInt(map1, "hasView") == 1 ? true : false);
                        oaEntity.setHasDownload(DBHelper.getValueInt(map1, "hasDownLoad") == 1 ? true : false);
                        oaEntity.setHasDelete(DBHelper.getValueInt(map1, "hasDelete") == 1 ? true : false);
                        oaEntity.setHasUpdate(DBHelper.getValueInt(map1,"hasUpdate") ==1 ? true : false);
                        String star = DBHelper.getValue(map1, "startDate");
                        oaEntity.setStartDate(StringUtils.isBlank(star) ? null : star.split(" ")[0]);
                        String end = DBHelper.getValue(map1, "endDate");
                        oaEntity.setEndDate(StringUtils.isBlank(end) ? null : end.split(" ")[0]);
                        oaEntity.setAllowViewNums(DBHelper.getValueInt(map1, "allowViewNums"));
                        oaEntity.setAllowDownNums(DBHelper.getValueInt(map1, "allowDownNums"));
                        oaEntity.setAllowUpdateNums(DBHelper.getValueInt(map1,"allowUpdateNums"));
                        oaEntity.setViewNums(DBHelper.getValueInt(map1,"viewNums"));
                        oaEntity.setDownNums(DBHelper.getValueInt(map1,"downNums"));
                        oaEntity.setUpdateNums(DBHelper.getValueInt(map1,"updateNums"));
                        Integer checked = DBHelper.getValueInt(map1, "checked");
                        oaEntity.setChecked(checked == 1 ? true : false);
                        if (checked == 0) {
                            check = false;
                        }
                        oaEntities.add(oaEntity);
                    }
                    map.put("checked", check);
                    map.put("info", oaEntities);
                    //把相同的value的map组装到out里
                    out.add(map);
                }
            }
        } catch (Exception e) {
            throw e;
        }
        return out;
    }
 
 
}