admin
2025-08-20 f318c9c7c127b00f353bf45f273096d1dc4b424f
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
package com.taoke.autopay.controller.admin.js2;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import com.taoke.autopay.dao.OrderTaskExecutionDetailMapper;
import com.taoke.autopay.dao.OrderTaskMapper;
import com.taoke.autopay.entity.js2.OrderTask;
import com.taoke.autopay.entity.js2.OrderTaskExecutionDetail;
import com.taoke.autopay.exception.OrderTaskException;
import com.taoke.autopay.factory.js2.OrderTaskFactory;
import com.taoke.autopay.service.js2.OrderTaskExecutionDetailService;
import com.taoke.autopay.service.js2.OrderTaskService;
import com.taoke.autopay.utils.TimeUtil;
import com.taoke.autopay.vo.admin.js2.OrderTaskVO;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.StringUtil;
 
import javax.annotation.Resource;
import java.io.IOException;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Calendar;
import java.util.ArrayList;
 
/**
 * 下单任务管理
 */
@Controller
@RequestMapping("/admin/api/ordertask/js2")
public class AdminOrderTaskController {
 
    @Resource
    private OrderTaskService orderTaskService;
    
    @Resource
    private OrderTaskExecutionDetailMapper orderTaskExecutionDetailMapper;
 
    private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new TypeAdapter<Date>() {
        @Override
        public void write(JsonWriter out, Date value) throws IOException {
            String desc = "";
            if (value != null) {
                // 判断是否是同一天
                desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss");
                out.value(desc);
            } else {
                out.value("");
            }
        }
 
        @Override
        public Date read(JsonReader in) throws IOException {
            return new Date();
        }
    }).create();
    @Autowired
    private OrderTaskExecutionDetailService orderTaskExecutionDetailService;
 
    /**
     * 任务列表查询(按照关键字,日期查询)
     */
    @ResponseBody
    @RequestMapping("list")
    public String list(String keyword, String startDate, String endDate, Integer status, int page, int limit) {
        try {
            OrderTaskMapper.DaoQuery query = new OrderTaskMapper.DaoQuery();
            if (!StringUtil.isNullOrEmpty(keyword)) {
                query.keywordContent = keyword;
            }
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            if (!StringUtil.isNullOrEmpty(startDate)) {
                query.minCreateTime = sdf.parse(startDate);
            }
            
            if (!StringUtil.isNullOrEmpty(endDate)) {
                Date end = sdf.parse(endDate);
                // 设置为当天的最后时刻
                Calendar cal = Calendar.getInstance();
                cal.setTime(end);
                cal.set(Calendar.HOUR_OF_DAY, 23);
                cal.set(Calendar.MINUTE, 59);
                cal.set(Calendar.SECOND, 59);
                query.maxCreateTime = cal.getTime();
            }
            
            if (status != null) {
                query.status = status;
            }
            
            query.sortList = Arrays.asList(new String[]{"create_time desc"});
            query.start = (page - 1) * limit;
            query.count = limit;
            
            List<OrderTask> list = orderTaskService.listOrderTasks(query, page, limit);
            long count = orderTaskService.countOrderTasks(query);
            
            // 转换为VO对象
            List<OrderTaskVO> voList = new ArrayList<>();
            for (OrderTask orderTask : list) {
                voList.add(OrderTaskFactory.createOrderTaskVO(orderTask));
            }
            
            JSONObject data = new JSONObject();
            data.put("list", gson.toJson(voList));
            data.put("count", count);
            return JsonUtil.loadTrueResult(data);
        } catch (ParseException e) {
            return JsonUtil.loadFalseResult("日期格式错误");
        } catch (Exception e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        }
    }
 
    /**
     * 获取单个任务信息
     */
    @ResponseBody
    @RequestMapping("get")
    public String get(Long id) {
        try {
            if (id == null) {
                return JsonUtil.loadFalseResult("任务ID不能为空");
            }
            
            OrderTask orderTask = orderTaskService.getOrderTaskById(id);
            if (orderTask == null) {
                return JsonUtil.loadFalseResult("任务不存在");
            }
            
            OrderTaskVO orderTaskVO = OrderTaskFactory.createOrderTaskVO(orderTask);
            return JsonUtil.loadTrueResult(gson.toJson(orderTaskVO));
        } catch (Exception e) {
            return JsonUtil.loadFalseResult("系统异常:" + e.getMessage());
        }
    }
 
    /**
     * 新增任务
     */
    @ResponseBody
    @RequestMapping("add")
    public String add(OrderTaskVO orderTaskVO) {
        try {
            if (orderTaskVO == null) {
                return JsonUtil.loadFalseResult("任务信息不能为空");
            }
            
            // 将VO转换为实体
            OrderTask orderTask = OrderTaskFactory.createOrderTask(orderTaskVO);
            OrderTask result = orderTaskService.createOrderTask(orderTask);
            OrderTaskVO resultVO = OrderTaskFactory.createOrderTaskVO(result);
            return JsonUtil.loadTrueResult(gson.toJson(resultVO));
        } catch (ParseException e) {
            return JsonUtil.loadFalseResult("日期格式错误:" + e.getMessage());
        } catch (OrderTaskException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        } catch (Exception e) {
            return JsonUtil.loadFalseResult("系统异常:" + e.getMessage());
        }
    }
 
    /**
     * 删除任务
     */
    @ResponseBody
    @RequestMapping("delete")
    public String delete(Long id) {
        try {
            if (id == null) {
                return JsonUtil.loadFalseResult("任务ID不能为空");
            }
            
            orderTaskService.deleteOrderTask(id);
            return JsonUtil.loadTrueResult("");
        } catch (OrderTaskException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        } catch (Exception e) {
            return JsonUtil.loadFalseResult("系统异常:" + e.getMessage());
        }
    }
 
    /**
     * 修改任务
     */
    @ResponseBody
    @RequestMapping("update")
    public String update(OrderTaskVO orderTaskVO) {
        try {
            if (orderTaskVO == null || orderTaskVO.getId() == null) {
                return JsonUtil.loadFalseResult("任务信息不完整");
            }
            
            // 先从数据库获取原始任务信息
            OrderTask orderTask = orderTaskService.getOrderTaskByIdForUpdate(orderTaskVO.getId());
            if (orderTask == null) {
                return JsonUtil.loadFalseResult("任务不存在");
            }
            OrderTask newOrderTask = OrderTaskFactory.createOrderTask(orderTaskVO);
            newOrderTask.setUpdateTime(new Date());
            orderTaskService.updateOrderTask(newOrderTask);
            return JsonUtil.loadTrueResult("");
        } catch (ParseException e) {
            return JsonUtil.loadFalseResult("日期格式错误:" + e.getMessage());
        } catch (OrderTaskException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        } catch (Exception e) {
            return JsonUtil.loadFalseResult("系统异常:" + e.getMessage());
        }
    }
 
    /**
     * 任务客户端分配
     */
    @ResponseBody
    @RequestMapping("assign")
    public String assign(Long taskId) {
        try {
            if (taskId == null) {
                return JsonUtil.loadFalseResult("任务ID不能为空");
            }
            
            int result = orderTaskService.assignTask(taskId);
            JSONObject data = new JSONObject();
            data.put("result", result);
            return JsonUtil.loadTrueResult(data);
        } catch (OrderTaskException e) {
            return JsonUtil.loadFalseResult(e.getMessage());
        } catch (Exception e) {
            return JsonUtil.loadFalseResult("系统异常:" + e.getMessage());
        }
    }
    
    /**
     * 查询任务已分配的客户端列表
     */
    @ResponseBody
    @RequestMapping("assignedClients")
    public String assignedClients(Long taskId, int page, int limit) {
        try {
            if (taskId == null) {
                return JsonUtil.loadFalseResult("任务ID不能为空");
            }
            
            OrderTaskExecutionDetailMapper.DaoQuery query = new OrderTaskExecutionDetailMapper.DaoQuery();
            query.taskId = taskId;
            query.start = (page - 1) * limit;
            query.count = limit;
            query.sortList = Arrays.asList("create_time desc");
            
            List<OrderTaskExecutionDetail> list = orderTaskExecutionDetailMapper.list(query);
            long count = orderTaskExecutionDetailMapper.count(query);
            
            JSONObject data = new JSONObject();
            data.put("list", gson.toJson(list));
            data.put("count", count);
            return JsonUtil.loadTrueResult(data);
        } catch (Exception e) {
            return JsonUtil.loadFalseResult("系统异常:" + e.getMessage());
        }
    }
 
    @ResponseBody
    @RequestMapping("updateExpectedReviewTime")
    public String updateExpectedReviewTime(String id, String expectedReviewTime) {
        try {
            if (StringUtil.isNullOrEmpty(id)) {
                return JsonUtil.loadFalseResult("ID不能为空");
            }
 
            OrderTaskExecutionDetail update =  OrderTaskExecutionDetail.builder()
                    .id( id)
                    .expectedReviewTime(new Date(TimeUtil.convertToTimeTemp(expectedReviewTime, "yyyy-MM-dd HH:mm:ss")))
                    .updateTime(new Date())
                    .build();
            orderTaskExecutionDetailService.updateOrderTaskExecutionDetail(update);
            return JsonUtil.loadTrueResult("");
        } catch (Exception e) {
            return JsonUtil.loadFalseResult("系统异常:" + e.getMessage());
        }
    }
 
 
}