xinyb
7 天以前 f632e7d7c25d8a86b1f6718f467bfef0d3c09058
提交 | 用户 | age
7cf738 1 package com.yc.crm.custom.action;
X 2
f632e7 3 import com.yc.crm.custom.entity.T480601Entity;
7cf738 4 import com.yc.crm.custom.service.CustomIfc;
X 5 import com.yc.crm.mail.entity.MailModuleEntity;
6 import com.yc.crm.mail.util.AllBackMsg;
7 import com.yc.entity.DataSourceEntity;
8 import com.yc.multiData.MultiDataSource;
9 import com.yc.multiData.SpObserver;
10 import com.yc.utils.SessionKey;
11 import org.apache.commons.lang3.StringUtils;
12 import org.springframework.beans.factory.annotation.Autowired;
13 import org.springframework.web.bind.annotation.*;
14
15 import javax.servlet.http.HttpServletRequest;
16 import javax.servlet.http.HttpServletResponse;
17 import javax.servlet.http.HttpSession;
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 /**
23  * @BelongsProject: eCoWorksV3
24  * @BelongsPackage: com.yc.crm.custom.action
25  * @author: xinyb
26  * @CreateTime: 2024-08-24  14:15
27  * @Description:
28  */
29 @CrossOrigin
30 @RestController
31 @RequestMapping("/crm/custom/")
32 public class CustomController {
33     @Autowired
34     CustomIfc customIfc;
35
36     /**
37      * 获取客户左边模块
38      *
39      * @return
40      */
41     @GetMapping("/getCustomModule.do")
42     public AllBackMsg getCustomModule(HttpServletRequest request, HttpServletResponse response) throws Exception {
43         AllBackMsg msg = new AllBackMsg();
44         try {
45             HttpSession session = request.getSession();
46             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
47             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
48                 msg.setFail("获取不到用户信息");
49                 return msg;
50             }
51             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
52             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
53             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
54             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
55             List<MailModuleEntity> list = null;
56             msg.setSuccess("执行成功", list);
57         } catch (Exception e) {
58             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
59         } finally {
60             SpObserver.setDBtoInstance();
61         }
62         return msg;
63     }
64
65     /**
66      * 保存客户
67      *
68      * @return
69      */
70     @PostMapping("/saveCustom.do")
f632e7 71     public AllBackMsg saveCustom(@RequestBody T480601Entity custom, HttpServletRequest request, HttpServletResponse response) throws Exception {
7cf738 72         AllBackMsg msg = new AllBackMsg();
X 73         try {
74             HttpSession session = request.getSession();
75             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
76             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
77                 msg.setFail("获取不到用户信息");
78                 return msg;
79             }
80             String userName = (String) session.getAttribute(SessionKey.USERNAME);
81             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
82             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
83             custom.setCompanyid(companyId);
84             custom.setCompanyname(companyName);
85             custom.setEnterCode(userCode);
86             custom.setEnterName(userName);
87             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
88             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
89             String docCode = customIfc.saveCustom(custom);
90             Map<String, Object> map = new HashMap<>();
91             if (StringUtils.isNotBlank(docCode)) {
92                 map.put("docCode", docCode);
93             }
94             msg.setSuccess("执行成功", map);
95         } catch (Exception e) {
96             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
97         } finally {
98             SpObserver.setDBtoInstance();
99         }
100         return msg;
101     }
102
103     /**
104      * 修改客户
105      *
106      * @return
107      */
108     @PostMapping("/updateCustom.do")
f632e7 109     public AllBackMsg updateCustom(@RequestBody T480601Entity custom, HttpServletRequest request, HttpServletResponse response) throws Exception {
7cf738 110         AllBackMsg msg = new AllBackMsg();
X 111         try {
112             HttpSession session = request.getSession();
113             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
114             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
115                 msg.setFail("获取不到用户信息");
116                 return msg;
117             }
118             if (StringUtils.isBlank(custom.getDocCode())) {
119                 msg.setFail("请输入修改的客户编号");
120                 return msg;
121             }
122             String userName = (String) session.getAttribute(SessionKey.USERNAME);
123             String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
124             String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
125             custom.setCompanyid(companyId);
126             custom.setCompanyname(companyName);
127             custom.setEnterCode(userCode);
128             custom.setEnterName(userName);
129             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
130             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
131             customIfc.updateCustom(custom);
132             msg.setSuccess("执行成功", "已保存");
133         } catch (Exception e) {
134             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
135         } finally {
136             SpObserver.setDBtoInstance();
137         }
138         return msg;
139     }
140
141     /**
142      * 删除客户
143      *
144      * @return
145      */
146     @PostMapping("/deleteCustom.do")
147     public AllBackMsg deleteCustom(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
148         AllBackMsg msg = new AllBackMsg();
149         try {
150             HttpSession session = request.getSession();
151             String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
152             if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
153                 msg.setFail("获取不到用户信息");
154                 return msg;
155             }
156             DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
157             SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
158             customIfc.deleteCustom(docCode, userCode);
159             msg.setSuccess("执行成功", "已保存");
160         } catch (Exception e) {
161             msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
162         } finally {
163             SpObserver.setDBtoInstance();
164         }
165         return msg;
166     }
167 }