xinyb
6 天以前 aad276da26b3b44b7622343fa0bf15583e803585
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
package com.yc.crm.mail.action;
 
//import com.yc.crm.mail.entity.T482115Entity;
 
import com.yc.crm.base.entity.T482115Entity;
import com.yc.crm.mail.entity.MailModuleBelowEntity;
import com.yc.crm.mail.service.MailTagIfc;
import com.yc.crm.mail.util.AllBackMsg;
import com.yc.entity.DataSourceEntity;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
import com.yc.utils.SessionKey;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @BelongsProject: eCoWorksV3
 * @BelongsPackage: com.yc.crm.mail.action
 * @author: xinyb
 * @CreateTime: 2024-09-04  15:22
 * @Description:标签
 */
@CrossOrigin
@RestController
@RequestMapping("/crm/mail/tag")
public class MailTag {
    @Autowired
    MailTagIfc mailTagIfc;
 
    /**
     * 添加标签
     *
     * @param signature
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/addTag.do")
    public AllBackMsg addTag(@RequestBody T482115Entity tag, HttpServletRequest request, HttpServletResponse response) {
        AllBackMsg msg = new AllBackMsg();
        try {
 
            HttpSession session = request.getSession();
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);
            String userName = (String) session.getAttribute(SessionKey.USER_NAME);
            tag.setCompanyId(companyId);
            tag.setCompanyName(companyName);
            tag.setUserCode(userCode);
            tag.setUserName(userName);
            DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
            SpObserver.setDBtoInstance("_" + dataSource.getDbId());
            //保存
            mailTagIfc.saveTag(tag);
            msg.setOk("已保存");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 修改标签
     *
     * @param signature
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/updateTag.do")
    public AllBackMsg updateTag(@RequestBody T482115Entity tag, HttpServletRequest request, HttpServletResponse response) {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (tag.getTagId() == null || tag.getTagId().equals(0)) {
                msg.setFail("缺少tagId值,请检查");
                return msg;
            }
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);
            if (StringUtils.isBlank(userCode)) {
                msg.setFail("登录用户已过期,请检查");
                return msg;
            }
            tag.setUserCode(userCode);
            DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
            SpObserver.setDBtoInstance("_" + dataSource.getDbId());
            mailTagIfc.updateTag(tag);
            msg.setOk("已更新");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 删除标签
     *
     * @param signId
     * @param request
     * @param response
     * @return
     */
    @PostMapping("/deleteTag.do")
    public AllBackMsg deleteTag(@RequestParam(defaultValue = "0") Integer tagId, HttpServletRequest request, HttpServletResponse response) {
        AllBackMsg msg = new AllBackMsg();
        try {
            if (tagId.equals(0)) {
                msg.setFail("标签ID获取不到");
                return msg;
            }
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);
            if (StringUtils.isBlank(userCode)) {
                msg.setFail("登录用户已过期,请检查");
                return msg;
            }
            DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
            SpObserver.setDBtoInstance("_" + dataSource.getDbId());
            Integer cont = mailTagIfc.deleteTag(userCode, tagId);
            if (cont > 0) {
                msg.setOk("已删除");
            }
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 标签查询
     *
     * @param search   搜索
     * @param request
     * @param response
     * @return
     */
    @GetMapping("/getTagList.do")
    public AllBackMsg getTagList(String search, @RequestParam(defaultValue = "-1") Integer type, HttpServletRequest request, HttpServletResponse response) {
        AllBackMsg msg = new AllBackMsg();
        try {
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);
            if (StringUtils.isBlank(userCode)) {
                msg.setFail("登录用户已过期,请检查");
                return msg;
            }
            DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源
            SpObserver.setDBtoInstance("_" + dataSource.getDbId());
            List<T482115Entity> list = mailTagIfc.getTagList(userCode, search, type);
            msg.setSuccess("执行成功", list);
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 标签树结构
     *
     * @param t482107
     * @param rowId
     * @return
     */
    public static List<MailModuleBelowEntity> getTagModule(List<T482115Entity> T482115) {
        List<MailModuleBelowEntity> tagList = new ArrayList<>();
        MailModuleBelowEntity tag1 = new MailModuleBelowEntity();
        tag1.setKey("systemTag");
        tag1.setType("tag");
        tag1.setName("系统标签");
        MailModuleBelowEntity tag2 = new MailModuleBelowEntity();
        tag2.setKey("customTag");
        tag2.setType("tag");
        tag2.setName("自定义标签");
        try {
            List<MailModuleBelowEntity> system = new ArrayList<>();
            List<MailModuleBelowEntity> custom = new ArrayList<>();
            for (T482115Entity t : T482115) {
                MailModuleBelowEntity tag = new MailModuleBelowEntity();
                tag.setId(t.getTagId());
                tag.setType("tag");
                tag.setName(t.getTagName());
                if (t.isSystemFlag()) {
                    tag.setKey("systemTag" + t.getTagId());
                    system.add(tag);
                } else {
                    tag.setKey("customTag" + t.getTagId());
                    custom.add(tag);
                }
            }
            tag1.setList(system);
            tag2.setList(custom);
            tagList.add(tag1);
            tagList.add(tag2);
            return tagList;
        } catch (Exception e) {
            throw e;
        }
    }
}