提交 | 用户 | age
|
428443
|
1 |
package com.yc.crm.mail.action; |
X |
2 |
|
6a63e2
|
3 |
//import com.yc.crm.mail.entity.T482115Entity; |
658898
|
4 |
|
6a63e2
|
5 |
import com.yc.crm.base.entity.T482115Entity; |
b7ef4b
|
6 |
import com.yc.crm.mail.entity.MailModuleBelowEntity; |
428443
|
7 |
import com.yc.crm.mail.service.MailTagIfc; |
X |
8 |
import com.yc.crm.mail.util.AllBackMsg; |
|
9 |
import com.yc.entity.DataSourceEntity; |
|
10 |
import com.yc.multiData.MultiDataSource; |
|
11 |
import com.yc.multiData.SpObserver; |
|
12 |
import com.yc.utils.SessionKey; |
|
13 |
import org.apache.commons.lang3.StringUtils; |
|
14 |
import org.springframework.beans.factory.annotation.Autowired; |
|
15 |
import org.springframework.web.bind.annotation.*; |
|
16 |
|
|
17 |
import javax.servlet.http.HttpServletRequest; |
|
18 |
import javax.servlet.http.HttpServletResponse; |
|
19 |
import javax.servlet.http.HttpSession; |
b7ef4b
|
20 |
import java.util.ArrayList; |
428443
|
21 |
import java.util.List; |
X |
22 |
|
|
23 |
/** |
|
24 |
* @BelongsProject: eCoWorksV3 |
|
25 |
* @BelongsPackage: com.yc.crm.mail.action |
|
26 |
* @author: xinyb |
|
27 |
* @CreateTime: 2024-09-04 15:22 |
|
28 |
* @Description:标签 |
|
29 |
*/ |
|
30 |
@CrossOrigin |
|
31 |
@RestController |
|
32 |
@RequestMapping("/crm/mail/tag") |
|
33 |
public class MailTag { |
|
34 |
@Autowired |
|
35 |
MailTagIfc mailTagIfc; |
|
36 |
|
|
37 |
/** |
|
38 |
* 添加标签 |
|
39 |
* |
|
40 |
* @param signature |
|
41 |
* @param request |
|
42 |
* @param response |
|
43 |
* @return |
|
44 |
*/ |
|
45 |
@PostMapping("/addTag.do") |
|
46 |
public AllBackMsg addTag(@RequestBody T482115Entity tag, HttpServletRequest request, HttpServletResponse response) { |
|
47 |
AllBackMsg msg = new AllBackMsg(); |
|
48 |
try { |
|
49 |
|
|
50 |
HttpSession session = request.getSession(); |
|
51 |
String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID); |
|
52 |
String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME); |
|
53 |
String userCode = (String) session.getAttribute(SessionKey.USERCODE); |
|
54 |
String userName = (String) session.getAttribute(SessionKey.USER_NAME); |
|
55 |
tag.setCompanyId(companyId); |
|
56 |
tag.setCompanyName(companyName); |
|
57 |
tag.setUserCode(userCode); |
|
58 |
tag.setUserName(userName); |
|
59 |
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源 |
|
60 |
SpObserver.setDBtoInstance("_" + dataSource.getDbId()); |
|
61 |
//保存 |
|
62 |
mailTagIfc.saveTag(tag); |
|
63 |
msg.setOk("已保存"); |
|
64 |
} catch (Exception e) { |
|
65 |
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
|
66 |
} finally { |
|
67 |
SpObserver.setDBtoInstance(); |
|
68 |
} |
|
69 |
return msg; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* 修改标签 |
|
74 |
* |
|
75 |
* @param signature |
|
76 |
* @param request |
|
77 |
* @param response |
|
78 |
* @return |
|
79 |
*/ |
|
80 |
@PostMapping("/updateTag.do") |
|
81 |
public AllBackMsg updateTag(@RequestBody T482115Entity tag, HttpServletRequest request, HttpServletResponse response) { |
|
82 |
AllBackMsg msg = new AllBackMsg(); |
|
83 |
try { |
658898
|
84 |
if (tag.getTagId() == null || tag.getTagId().equals(0)) { |
5b1a4a
|
85 |
msg.setFail("缺少tagId值,请检查"); |
428443
|
86 |
return msg; |
X |
87 |
} |
|
88 |
HttpSession session = request.getSession(); |
|
89 |
String userCode = (String) session.getAttribute(SessionKey.USERCODE); |
|
90 |
if (StringUtils.isBlank(userCode)) { |
|
91 |
msg.setFail("登录用户已过期,请检查"); |
|
92 |
return msg; |
|
93 |
} |
|
94 |
tag.setUserCode(userCode); |
|
95 |
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源 |
|
96 |
SpObserver.setDBtoInstance("_" + dataSource.getDbId()); |
|
97 |
mailTagIfc.updateTag(tag); |
|
98 |
msg.setOk("已更新"); |
|
99 |
} catch (Exception e) { |
|
100 |
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
|
101 |
} finally { |
|
102 |
SpObserver.setDBtoInstance(); |
|
103 |
} |
|
104 |
return msg; |
|
105 |
} |
|
106 |
|
|
107 |
/** |
|
108 |
* 删除标签 |
|
109 |
* |
|
110 |
* @param signId |
|
111 |
* @param request |
|
112 |
* @param response |
|
113 |
* @return |
|
114 |
*/ |
|
115 |
@PostMapping("/deleteTag.do") |
|
116 |
public AllBackMsg deleteTag(@RequestParam(defaultValue = "0") Integer tagId, HttpServletRequest request, HttpServletResponse response) { |
|
117 |
AllBackMsg msg = new AllBackMsg(); |
|
118 |
try { |
658898
|
119 |
if (tagId.equals(0)) { |
5b1a4a
|
120 |
msg.setFail("标签ID获取不到"); |
428443
|
121 |
return msg; |
X |
122 |
} |
|
123 |
HttpSession session = request.getSession(); |
|
124 |
String userCode = (String) session.getAttribute(SessionKey.USERCODE); |
|
125 |
if (StringUtils.isBlank(userCode)) { |
|
126 |
msg.setFail("登录用户已过期,请检查"); |
|
127 |
return msg; |
|
128 |
} |
|
129 |
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源 |
|
130 |
SpObserver.setDBtoInstance("_" + dataSource.getDbId()); |
|
131 |
Integer cont = mailTagIfc.deleteTag(userCode, tagId); |
|
132 |
if (cont > 0) { |
|
133 |
msg.setOk("已删除"); |
|
134 |
} |
|
135 |
} catch (Exception e) { |
|
136 |
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
|
137 |
} finally { |
|
138 |
SpObserver.setDBtoInstance(); |
|
139 |
} |
|
140 |
return msg; |
|
141 |
} |
|
142 |
|
|
143 |
/** |
|
144 |
* 标签查询 |
658898
|
145 |
* |
428443
|
146 |
* @param search 搜索 |
X |
147 |
* @param request |
|
148 |
* @param response |
|
149 |
* @return |
|
150 |
*/ |
|
151 |
@GetMapping("/getTagList.do") |
b7ef4b
|
152 |
public AllBackMsg getTagList(String search, @RequestParam(defaultValue = "-1") Integer type, HttpServletRequest request, HttpServletResponse response) { |
428443
|
153 |
AllBackMsg msg = new AllBackMsg(); |
X |
154 |
try { |
|
155 |
HttpSession session = request.getSession(); |
|
156 |
String userCode = (String) session.getAttribute(SessionKey.USERCODE); |
|
157 |
if (StringUtils.isBlank(userCode)) { |
|
158 |
msg.setFail("登录用户已过期,请检查"); |
|
159 |
return msg; |
|
160 |
} |
|
161 |
DataSourceEntity dataSource = MultiDataSource.getDataSourceMap(request);//获取数据源 |
|
162 |
SpObserver.setDBtoInstance("_" + dataSource.getDbId()); |
b7ef4b
|
163 |
List<T482115Entity> list = mailTagIfc.getTagList(userCode, search, type); |
428443
|
164 |
msg.setSuccess("执行成功", list); |
X |
165 |
} catch (Exception e) { |
|
166 |
msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage()); |
|
167 |
} finally { |
|
168 |
SpObserver.setDBtoInstance(); |
|
169 |
} |
|
170 |
return msg; |
|
171 |
} |
b7ef4b
|
172 |
|
X |
173 |
/** |
|
174 |
* 标签树结构 |
|
175 |
* |
|
176 |
* @param t482107 |
|
177 |
* @param rowId |
|
178 |
* @return |
|
179 |
*/ |
|
180 |
public static List<MailModuleBelowEntity> getTagModule(List<T482115Entity> T482115) { |
|
181 |
List<MailModuleBelowEntity> tagList = new ArrayList<>(); |
|
182 |
MailModuleBelowEntity tag1 = new MailModuleBelowEntity(); |
|
183 |
tag1.setKey("systemTag"); |
aad276
|
184 |
tag1.setType("tag"); |
b7ef4b
|
185 |
tag1.setName("系统标签"); |
X |
186 |
MailModuleBelowEntity tag2 = new MailModuleBelowEntity(); |
|
187 |
tag2.setKey("customTag"); |
aad276
|
188 |
tag2.setType("tag"); |
b7ef4b
|
189 |
tag2.setName("自定义标签"); |
X |
190 |
try { |
|
191 |
List<MailModuleBelowEntity> system = new ArrayList<>(); |
|
192 |
List<MailModuleBelowEntity> custom = new ArrayList<>(); |
|
193 |
for (T482115Entity t : T482115) { |
|
194 |
MailModuleBelowEntity tag = new MailModuleBelowEntity(); |
aad276
|
195 |
tag.setId(t.getTagId()); |
X |
196 |
tag.setType("tag"); |
b7ef4b
|
197 |
tag.setName(t.getTagName()); |
X |
198 |
if (t.isSystemFlag()) { |
|
199 |
tag.setKey("systemTag" + t.getTagId()); |
|
200 |
system.add(tag); |
|
201 |
} else { |
|
202 |
tag.setKey("customTag" + t.getTagId()); |
|
203 |
custom.add(tag); |
|
204 |
} |
|
205 |
} |
|
206 |
tag1.setList(system); |
|
207 |
tag2.setList(custom); |
|
208 |
tagList.add(tag1); |
|
209 |
tagList.add(tag2); |
|
210 |
return tagList; |
|
211 |
} catch (Exception e) { |
|
212 |
throw e; |
|
213 |
} |
|
214 |
} |
428443
|
215 |
} |