xinyb
7 天以前 f632e7d7c25d8a86b1f6718f467bfef0d3c09058
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
package com.yc.crm.custom.action;
 
import com.yc.crm.custom.entity.T480601Entity;
import com.yc.crm.custom.service.CustomIfc;
import com.yc.crm.mail.entity.MailModuleEntity;
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.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @BelongsProject: eCoWorksV3
 * @BelongsPackage: com.yc.crm.custom.action
 * @author: xinyb
 * @CreateTime: 2024-08-24  14:15
 * @Description:
 */
@CrossOrigin
@RestController
@RequestMapping("/crm/custom/")
public class CustomController {
    @Autowired
    CustomIfc customIfc;
 
    /**
     * 获取客户左边模块
     *
     * @return
     */
    @GetMapping("/getCustomModule.do")
    public AllBackMsg getCustomModule(HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
            if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
                msg.setFail("获取不到用户信息");
                return msg;
            }
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            List<MailModuleEntity> list = null;
            msg.setSuccess("执行成功", list);
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 保存客户
     *
     * @return
     */
    @PostMapping("/saveCustom.do")
    public AllBackMsg saveCustom(@RequestBody T480601Entity custom, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
            if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
                msg.setFail("获取不到用户信息");
                return msg;
            }
            String userName = (String) session.getAttribute(SessionKey.USERNAME);
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
            custom.setCompanyid(companyId);
            custom.setCompanyname(companyName);
            custom.setEnterCode(userCode);
            custom.setEnterName(userName);
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            String docCode = customIfc.saveCustom(custom);
            Map<String, Object> map = new HashMap<>();
            if (StringUtils.isNotBlank(docCode)) {
                map.put("docCode", docCode);
            }
            msg.setSuccess("执行成功", map);
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 修改客户
     *
     * @return
     */
    @PostMapping("/updateCustom.do")
    public AllBackMsg updateCustom(@RequestBody T480601Entity custom, HttpServletRequest request, HttpServletResponse response) throws Exception {
        AllBackMsg msg = new AllBackMsg();
        try {
            HttpSession session = request.getSession();
            String userCode = (String) session.getAttribute(SessionKey.USERCODE);//当前登录用户
            if (StringUtils.isBlank(userCode)) {//获取不到当前用户直接结束
                msg.setFail("获取不到用户信息");
                return msg;
            }
            if (StringUtils.isBlank(custom.getDocCode())) {
                msg.setFail("请输入修改的客户编号");
                return msg;
            }
            String userName = (String) session.getAttribute(SessionKey.USERNAME);
            String companyId = (String) session.getAttribute(SessionKey.COMPANY_ID);
            String companyName = (String) session.getAttribute(SessionKey.COMPANY_NAME);
            custom.setCompanyid(companyId);
            custom.setCompanyname(companyName);
            custom.setEnterCode(userCode);
            custom.setEnterName(userName);
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            customIfc.updateCustom(custom);
            msg.setSuccess("执行成功", "已保存");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
 
    /**
     * 删除客户
     *
     * @return
     */
    @PostMapping("/deleteCustom.do")
    public AllBackMsg deleteCustom(String docCode, HttpServletRequest request, HttpServletResponse response) throws Exception {
        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 dataSourceEntity = MultiDataSource.getDataSourceMap(request);//获取数据源信息
            SpObserver.setDBtoInstance("_" + dataSourceEntity.getDbId());//切换数据源
            customIfc.deleteCustom(docCode, userCode);
            msg.setSuccess("执行成功", "已保存");
        } catch (Exception e) {
            msg.setFail(e.getCause() != null ? e.getCause().getMessage() : e.getMessage());
        } finally {
            SpObserver.setDBtoInstance();
        }
        return msg;
    }
}