cy
2022-06-28 2ba5c891b24d4d0cd6ce7ef833592e4f576ee5e8
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
package cn.ksource.web.facade.traffic;
 
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import java.util.TimeZone;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import cn.ksource.core.dao.BaseDao;
import cn.ksource.core.page.PageInfo;
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.DateUtil;
import cn.ksource.core.util.StringUtil;
import cn.ksource.web.Constants;
 
@Service
public class TrafficFacadeImpl implements TrafficFacade{
    @Autowired
    private BaseDao baseDao;
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public PageInfo getTrafficData(Map param, PageInfo pageInfo) {
        String sql="select a.*,e.bid tid,e.order_code,e.BUSINESSTYPE,e.BUSINESS_ID,e.cid from traffic a " +
                " left join (select b.tra_id,b.id bid,c.order_code,d.BUSINESSTYPE,d.id BUSINESS_ID,c.id cid from sc_workflow_incident c,workflow_base d,traffic_ref b" +
                " where c.id=d.BUSINESS_ID and b.order_id=c.id ) e on e.tra_id=a.id " +
                " where 1=1 ";
        String start_time=ConvertUtil.obj2StrBlank(param.get("start_time"));
        String end_time=ConvertUtil.obj2StrBlank(param.get("end_time"));
        String mobile=ConvertUtil.obj2StrBlank(param.get("mobile"));
        if(StringUtil.notEmpty(start_time)){
            start_time+="000000";
            param.put("start_time", start_time);
            sql+=" and a.create_time>:start_time ";
        }
        if(StringUtil.notEmpty(end_time)){
            end_time+="235959";
            param.put("end_time", end_time);
            sql+=" and a.create_time<:end_time ";
        }
        if(StringUtil.notEmpty(mobile)){
            sql+=" and a.CUSTOMER_MOBILE=:mobile ";
        }
        String customer_mobile=ConvertUtil.obj2StrBlank(param.get("customer_mobile"));
        if(StringUtil.notEmpty(customer_mobile)){
            sql+=" and a.CUSTOMER_MOBILE=:customer_mobile ";
        }
        String user_name=ConvertUtil.obj2StrBlank(param.get("user_name"));
        if(StringUtil.notEmpty(user_name)){
            param.put("user_name", "%"+user_name+"%");
            sql+=" and a.user_name like :user_name ";
        }
        String tra_state=ConvertUtil.obj2StrBlank(param.get("tra_state"));
        if(StringUtil.notEmpty(tra_state)){
            sql+=" and a.tra_state=:tra_state ";
        }
        sql+=" order by a.create_time desc ";
        return baseDao.queryforSplitPageInfo(pageInfo, sql, param);
        
    }
 
    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public int getTrafficCount(Map param) {
        String sql="select count(id) from traffic where 1=1 ";
        String start_time=ConvertUtil.obj2StrBlank(param.get("start_time"));
        String end_time=ConvertUtil.obj2StrBlank(param.get("end_time"));
        String mobile=ConvertUtil.obj2StrBlank(param.get("mobile"));
        if(StringUtil.notEmpty(start_time)){
            start_time+="000000";
            param.put("start_time", start_time);
            sql+=" and create_time>:start_time ";
        }
        if(StringUtil.notEmpty(end_time)){
            end_time+="235959";
            param.put("end_time", end_time);
            sql+=" and create_time<:end_time ";
        }
        if(StringUtil.notEmpty(mobile)){
            sql+=" and CUSTOMER_MOBILE=:mobile ";
        }
        String customer_mobile=ConvertUtil.obj2StrBlank(param.get("customer_mobile"));
        if(StringUtil.notEmpty(customer_mobile)){
            sql+=" and CUSTOMER_MOBILE=:customer_mobile ";
        }
        String user_name=ConvertUtil.obj2StrBlank(param.get("user_name"));
        if(StringUtil.notEmpty(user_name)){
            param.put("user_name", "%"+user_name+"%");
            sql+=" and user_name like :user_name ";
        }
        String tra_state=ConvertUtil.obj2StrBlank(param.get("tra_state"));
        if(StringUtil.notEmpty(tra_state)){
            sql+=" and tra_state=:tra_state ";
        }
        return baseDao.queryForInteger(sql, param);
    }
 
    @SuppressWarnings("rawtypes")
    @Override
    public Map getTraffic(Map param) {
        String sql="select * from traffic where id=:id ";
        return baseDao.queryForMap(sql, param);
    }
 
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public PageInfo getTrafficOrderData(Map param, PageInfo pageInfo) {
        String sql="select a.*,c.ID BUSINESS_ID,c.BUSINESSTYPE BUSINESSTYPE,c.WFSTATE WFSTATE from sc_workflow_incident a,traffic_ref b,workflow_base c where a.order_code=b.order_code and a.id=c.business_id ";
        String order_name=ConvertUtil.obj2StrBlank(param.get("order_name"));
        String order_code=ConvertUtil.obj2StrBlank(param.get("order_code"));
        String mobile=ConvertUtil.obj2StrBlank(param.get("mobile"));
        if(StringUtil.notEmpty(order_name)){
            param.put("order_name", "%"+order_name+"%");
            sql+=" and a.NAME like :order_name";
        }
        if(StringUtil.notEmpty(order_code)){
            sql+=" and a.order_code=:order_code ";
        }
        if(StringUtil.notEmpty(mobile)){
            sql+=" and b.mobile=:mobile ";
        }
        sql+=" order by a.CREATE_TIME DESC";
        return baseDao.queryforSplitPageInfo(pageInfo, sql, param);
    }
 
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public int getTrafficOrderCount(Map param) {
        String sql="select count(a.id) from sc_workflow_incident a,traffic_ref b,workflow_base c where a.order_code=b.order_code and a.id=c.business_id ";
        String order_name=ConvertUtil.obj2StrBlank(param.get("order_name"));
        String order_code=ConvertUtil.obj2StrBlank(param.get("order_code"));
        String mobile=ConvertUtil.obj2StrBlank(param.get("mobile"));
        if(StringUtil.notEmpty(order_name)){
            param.put("order_name", "%"+order_name+"%");
            sql+=" and a.NAME like :order_name";
        }
        if(StringUtil.notEmpty(order_code)){
            sql+=" and a.order_code=:order_code ";
        }
        if(StringUtil.notEmpty(mobile)){
            sql+=" and b.mobile=:mobile ";
        }
        return baseDao.queryForInteger(sql, param);
    }
 
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public Map getTrafficNum(Map param) {
        String start_time=ConvertUtil.obj2Str(DateUtil.getCurrentDate8())+"000000";
        String end_time=ConvertUtil.obj2Str(DateUtil.getCurrentDate8())+"235959";
        Map result=new HashMap();
        param.put("start_time", start_time);
        param.put("end_time", end_time);
        String sql="select count(id) from traffic where create_time>:start_time and create_time<:end_time and tra_state=1 ";
        //今日通话数
        int count=baseDao.queryForInteger(sql, param);
        result.put("count", count);
        String sqla="select count(id) from traffic where create_time>:start_time and create_time<:end_time and (tra_state=0 or tra_state is null) ";
        //今日未通话
        int count1=baseDao.queryForInteger(sqla, param);
        result.put("count1", count1);
        String sqlb="select count(id) from traffic where create_time>:start_time and create_time<:end_time  ";
        //今日总数
        int countNum=baseDao.queryForInteger(sqlb, param);
        result.put("countNum", countNum);
        String sqlc="select count(a.id) from traffic a,traffic_ref b where a.create_time>:start_time and a.create_time<:end_time and a.id=b.tra_id  ";
        //今日生成工单
        int countOrder=baseDao.queryForInteger(sqlc, param);
        result.put("countOrder", countOrder);
        
        
        
        String sqld="select count(id) from traffic where tra_state=1 ";
        //通话数
        int num=baseDao.queryForInteger(sqld, param);
        result.put("num", num);
        String sqle="select count(id) from traffic where tra_state=0 or tra_state is null ";
        //今日未通话
        int num1=baseDao.queryForInteger(sqle, param);
        result.put("num1", num1);
        String sqlf="select count(id) from traffic where 1=1  ";
        //总数
        int numSum=baseDao.queryForInteger(sqlf, param);
        result.put("numSum", numSum);
        
        String sqlg="select count(a.id) from traffic a,traffic_ref b where a.id=b.tra_id  ";
        //今日生成工单
        int numOrder=baseDao.queryForInteger(sqlg, param);
        result.put("numOrder", numOrder);
        return result;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public Map saveTraffic(Map param) {
        String id=StringUtil.getUUID();
        param.put("id", id);
        param.put("create_time", DateUtil.getCurrentDate14());
        String sql="insert into traffic(ID,SERIAL_NUMBER,CUSTOMER_MOBILE,TRA_STATE,USER_ID,USER_NAME," +
                "ORDER_STATE,CREATE_TIME,START_TIME) values(:id,:sn,:ph,0,:userId,:userName,0,:create_time,:tm)";
        baseDao.execute(sql, param);
        Map result=new HashMap();
        result.put("id", id);
        result.put("mobile", param.get("ph"));
        return result;
    }
 
    @SuppressWarnings("unchecked")
    @Override
    public void updateTraffic(Map param) {
        String time=ConvertUtil.obj2StrBlank(param.get("time")).replace(":", "");
//        if(StringUtil.isEmpty(time)){
//            time=ConvertUtil.obj2StrBlank(DateUtil.getCurrentDate14()).substring(8, 14);
//        }
        String now=ConvertUtil.obj2StrBlank(DateUtil.getCurrentDate8())+time;
        param.put("now", now);
        String sql="update traffic set TRA_STATE=1,END_TIME=:now where SERIAL_NUMBER=:sn";
        baseDao.execute(sql, param);
        String sqla="select * from traffic where SERIAL_NUMBER=:sn ";
        Map map=baseDao.queryForMap(sqla, param);
        if(StringUtil.notEmpty(ConvertUtil.obj2StrBlank(map.get("START_TIME")))){
            if(StringUtil.notEmpty(ConvertUtil.obj2StrBlank(map.get("END_TIME")))){
                long s=DateUtil.getMillisFormDate2Date(ConvertUtil.obj2Long(map.get("START_TIME")),
                        ConvertUtil.obj2Long(map.get("END_TIME")));
                SimpleDateFormat format=new SimpleDateFormat("HH:mm:ss");
                format.setTimeZone(TimeZone.getTimeZone("GMT_00:00"));
                String hs=format.format(s);
                param.put("hs", hs);
                String sqlb="update traffic set LONG_TIME=:hs where SERIAL_NUMBER=:sn";
                baseDao.execute(sqlb, param);
            }
        }
    }
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public PageInfo getTrafficOrderDataTwo(Map param, PageInfo pageInfo) {
        String sql="select a.*,c.ID BUSINESS_ID,c.BUSINESSTYPE BUSINESSTYPE,c.WFSTATE WFSTATE from sc_workflow_incident a,workflow_base c where a.id=c.business_id ";
        String order_name=ConvertUtil.obj2StrBlank(param.get("order_name"));
        String order_code=ConvertUtil.obj2StrBlank(param.get("order_code"));
        String mobile=ConvertUtil.obj2StrBlank(param.get("mobile"));
        if(StringUtil.notEmpty(order_name)){
            param.put("order_name", "%"+order_name+"%");
            sql+=" and a.NAME like :order_name";
        }
        if(StringUtil.notEmpty(order_code)){
            sql+=" and a.order_code=:order_code ";
        }
        if(StringUtil.notEmpty(mobile)){
            sql+=" and a.CONTACT_PHONE=:mobile ";
        }
        sql+=" order by a.CREATE_TIME DESC";
        return baseDao.queryforSplitPageInfo(pageInfo, sql, param);
    }
    @SuppressWarnings({ "unchecked", "rawtypes" })
    @Override
    public int getTrafficOrderCountTwo(Map param) {
        String sql="select count(a.id) from sc_workflow_incident a,workflow_base c where a.id=c.business_id ";
        String order_name=ConvertUtil.obj2StrBlank(param.get("order_name"));
        String order_code=ConvertUtil.obj2StrBlank(param.get("order_code"));
        String mobile=ConvertUtil.obj2StrBlank(param.get("mobile"));
        if(StringUtil.notEmpty(order_name)){
            param.put("order_name", "%"+order_name+"%");
            sql+=" and a.NAME like :order_name";
        }
        if(StringUtil.notEmpty(order_code)){
            sql+=" and a.order_code=:order_code ";
        }
        if(StringUtil.notEmpty(mobile)){
            sql+=" and a.CONTACT_PHONE=:mobile ";
        }
        return baseDao.queryForInteger(sql, param);
    }
}