package com.taoke.autopay.controller.admin;
|
|
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.KeyOrderMapper;
|
import com.taoke.autopay.dao.WxUserInfoMapper;
|
import com.taoke.autopay.entity.*;
|
import com.taoke.autopay.factory.OrderFactory;
|
import com.taoke.autopay.factory.WxUserFactory;
|
import com.taoke.autopay.service.AdminUserService;
|
import com.taoke.autopay.service.ClientInfoService;
|
import com.taoke.autopay.service.KeyOrderService;
|
import com.taoke.autopay.utils.TimeUtil;
|
import com.taoke.autopay.vo.AdminOrderVO;
|
import com.taoke.autopay.vo.WxUserVO;
|
import net.sf.json.JSONObject;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.validation.BindingResult;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.NumberUtil;
|
import org.yeshi.utils.StringUtil;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpSession;
|
import javax.validation.constraints.NotEmpty;
|
import java.io.IOException;
|
import java.util.*;
|
|
@Controller
|
@RequestMapping("/admin/api/order")
|
public class AdminOrderController {
|
|
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();
|
|
@Resource
|
private KeyOrderService keyOrderService;
|
@Resource
|
private ClientInfoService clientInfoService;
|
|
|
@ResponseBody
|
@RequestMapping("list")
|
public String listOrder(String key, int page, int limit) {
|
//先查询所有的数据
|
KeyOrderMapper.DaoQuery query = new KeyOrderMapper.DaoQuery();
|
query.sortList=Arrays.asList(new String[]{"create_time desc"});
|
query.start = (page - 1) * limit;
|
query.count = limit;
|
if (!StringUtil.isNullOrEmpty(key)) {
|
if (key.length() > 10 || !NumberUtil.isNumeric(key.trim())) {
|
// 订单号
|
query.orderNo = key.trim();
|
} else {
|
// 用户ID
|
query.uid = Long.parseLong(key.trim());
|
}
|
}
|
|
List<KeyOrder> orderList = keyOrderService.list(query);
|
long count = keyOrderService.count(query);
|
Map<Long, ClientInfo> clientMap = new HashMap<>();
|
if (orderList.size() > 0) {
|
List<Long> cids = new ArrayList<>();
|
for (KeyOrder u : orderList) {
|
if (u.getDistributeClientUid() != null) {
|
cids.add(u.getDistributeClientUid());
|
}
|
}
|
List<ClientInfo> clients = clientInfoService.listByIds(cids);
|
for (ClientInfo client : clients) {
|
clientMap.put(client.getId(), client);
|
}
|
}
|
|
// 转vo
|
List<AdminOrderVO> voList = new ArrayList<>();
|
for (KeyOrder order : orderList) {
|
voList.add(OrderFactory.createAdminVO(order, clientMap.get(order.getDistributeClientUid())));
|
}
|
JSONObject data = new JSONObject();
|
data.put("count", count);
|
data.put("list", gson.toJson(voList));
|
return JsonUtil.loadTrueResult(data);
|
}
|
|
}
|