1
zj
2025-03-20 697c08d94a3c26aaa970c467775989bb548fb6c2
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
package project.web.admin.systemuser;
 
import javax.servlet.http.HttpServletRequest;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
import kernel.exception.BusinessException;
import kernel.util.DateUtils;
import kernel.web.PageActionSupport;
import systemuser.AdminCustomerService;
import systemuser.CustomerService;
import systemuser.model.Customer;
 
/**
 * 客服个人中心
 *
 */
@RestController
public class AdminPersonalCustomerController extends PageActionSupport {
    
    private Logger logger=LoggerFactory.getLogger(AdminPersonalCustomerController.class);
    
    @Autowired
    private AdminCustomerService adminCustomerService;
    
    @Autowired
    private CustomerService customerService;
    
    private final String action = "normal/adminPersonalCustomerAction!";
    
    /**
     * 点击客服中心
     */
    @RequestMapping(action + "personalCustomer.action")
    public ModelAndView personalCustomer(HttpServletRequest request) {
        
        String message = request.getParameter("message");
        String error = request.getParameter("error");
        
        boolean off_to_online = true;
        if("/normal/adminPersonalCustomerAction!personalCustomer.action".equals(request.getServletPath())) {
            off_to_online = false;
        }
        
        String username = null;
        String last_online_time = null;
        String last_offline_time = null;
        String auto_answer = null;
        Integer online_state = null;
        ModelAndView model = new ModelAndView();
        
        try {
            Customer customer = this.customerService.cacheByUsername(this.getUsername_login());
            if (null != customer) {
                last_online_time = DateUtils.format(customer.getLast_online_time(), DateUtils.DF_yyyyMMddHHmmss);
                last_offline_time = DateUtils.format(customer.getLast_offline_time(), DateUtils.DF_yyyyMMddHHmmss);
                auto_answer = customer.getAuto_answer();
                online_state = customer.getOnline_state();
            }
            username = this.getUsername_login();
        } catch (BusinessException e) {
            error = e.getMessage();
        } catch (Throwable t) {
            logger.error(" error ", t);
            error = ("[ERROR] " + t.getMessage());
        }
        
        model.addObject("off_to_online", off_to_online);
        model.addObject("username", username);
        model.addObject("last_online_time", last_online_time);
        model.addObject("last_offline_time", last_offline_time);
        model.addObject("auto_answer", auto_answer);
        model.addObject("online_state", online_state);
        
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("personal_customer");
        return model;
    }
    
    /**
     * 上线
     */
    @RequestMapping(action + "personalOnline.action")
    public ModelAndView personalOnline() {
        
        String message = "";
        String error = "";
        boolean off_to_online = false;
        try {
            this.adminCustomerService.online(this.getUsername_login());
            off_to_online = true;
            message = "操作成功";
        } catch (BusinessException e) {
            error = e.getMessage();
        } catch (Throwable t) {
            logger.error(" error ", t);
            error = ("[ERROR] " + t.getMessage());
        }
        ModelAndView model = new ModelAndView();
        model.addObject("off_to_online", off_to_online);
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("redirect:/" + action + "personalCustomer.action");
        return model;
    }
    
    /**
     * 下线
     */
    @RequestMapping(action + "personalOffline.action")
    public ModelAndView personalOffline() {
        String message = "";
        String error = "";
        boolean off_to_online = true;
        try {
            this.adminCustomerService.offline(this.getUsername_login());
            off_to_online = false;
            message = "操作成功";
        } catch (BusinessException e) {
            error = e.getMessage();
        } catch (Throwable t) {
            logger.error(" error ", t);
            error = ("[ERROR] " + t.getMessage());
        }
        ModelAndView model = new ModelAndView();
        model.addObject("off_to_online", off_to_online);
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("redirect:/" + action + "personalCustomer.action");
        return model;
    }
 
    @RequestMapping(action + "personalUpdateAutoAnswer.action")
    public ModelAndView personalUpdateAutoAnswer(HttpServletRequest request) {
        String message = "";
        String error = "";
        String login_safeword = request.getParameter("login_safeword");
        String auto_answer = request.getParameter("auto_answer");
        boolean off_to_online = true;
        try {
            adminCustomerService.updatePersonalAutoAnswer(this.getUsername_login(), login_safeword, 
                    this.getIp(), auto_answer);
            off_to_online = false;
            message = "操作成功";
        } catch (BusinessException e) {
            error = e.getMessage();
        } catch (Throwable t) {
            logger.error(" error ", t);
            error = ("[ERROR] " + t.getMessage());
        }
        ModelAndView model = new ModelAndView();
        model.addObject("off_to_online", off_to_online);
        model.addObject("message", message);
        model.addObject("error", error);
        model.setViewName("redirect:/" + action + "personalCustomer.action");
        return model;
    }
 
    public Integer customerOnlineState() {
        Customer customer = customerService.cacheByUsername(this.getUsername_login());
        if(null == customer) {
            return null;
        }
        return customer.getOnline_state();
    }
 
}