package com.yeshi.fanli.controller.admin.order;
|
|
import java.io.PrintWriter;
|
import java.lang.reflect.Type;
|
import java.util.Date;
|
import java.util.HashSet;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Set;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.yeshi.utils.JsonUtil;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.JsonElement;
|
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializer;
|
import com.yeshi.fanli.entity.taobao.TaoBaoOrder;
|
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
|
import com.yeshi.fanli.job.order.taobao.UpdateOrderJob;
|
import com.yeshi.fanli.job.order.taobao.UpdateTBRelationAndSpecialOrderJob;
|
import com.yeshi.fanli.service.inter.order.tb.TaoBaoOrderService;
|
import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
|
import com.yeshi.fanli.tag.PageEntity;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.TimeUtil;
|
|
import net.sf.json.JSONObject;
|
|
@Controller
|
@RequestMapping("admin/new/api/v1/taobaoOrder")
|
public class TaoBaoOrderController {
|
|
@Resource
|
private TaoBaoOrderService taoBaoOrderService;
|
|
@Resource
|
private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
|
|
@Resource
|
private UpdateTBRelationAndSpecialOrderJob updateRelationAndSpecialOrderJob;
|
|
@Resource
|
private UpdateOrderJob updateOrderJob;
|
|
/**
|
* 查询列表 - 新后台
|
*
|
* @param callback
|
* @param key
|
* 查询词 名称
|
* @param pageIndex
|
* @param out
|
*/
|
@RequestMapping(value = "listTaoBaoOrder")
|
public void listTaoBaoOrder(String callback, String key, Integer pageIndex, PrintWriter out) {
|
|
try {
|
|
if (pageIndex == null || pageIndex < 0) {
|
pageIndex = 1;
|
}
|
|
List<TaoBaoOrder> orderList = null;
|
Long count = null;
|
|
if (!StringUtil.isNullOrEmpty(key)) {
|
orderList = taoBaoOrderService.getTaoBaoOrderByOrderId(key);
|
count = (long) orderList.size();
|
} else {
|
orderList = taoBaoOrderService.listAllOrder(pageIndex, Constant.PAGE_SIZE);
|
count = taoBaoOrderService.countAllOrder();
|
}
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
|
PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
|
|
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
@Override
|
public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
|
if (value == null) {
|
return new JsonPrimitive("");
|
} else {
|
return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"));
|
}
|
}
|
}).create();
|
|
JSONObject data = new JSONObject();
|
data.put("pe", pe);
|
data.put("result_list", gson.toJson(orderList));
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
e.printStackTrace();
|
}
|
}
|
|
@RequestMapping(value = "updateTaoBaoOrder")
|
public void updateTaoBaoOrder(String callback, String ids, PrintWriter out) {
|
try {
|
if (StringUtil.isNullOrEmpty(ids)) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("请上传订单ID"));
|
return;
|
}
|
net.sf.json.JSONArray idsArray = net.sf.json.JSONArray.fromObject(ids);
|
|
Set<String> orderIds = new HashSet<>();
|
|
for (int i = 0; i < idsArray.size(); i++) {
|
TaoBaoOrder taoBaoOrder = taoBaoOrderService.selectByPrimaryKey(idsArray.optLong(i));
|
orderIds.add(taoBaoOrder.getOrderId());
|
}
|
|
Long[] startTimes = new Long[orderIds.size()];
|
Long[] endTimes = new Long[orderIds.size()];
|
|
int p = 0;
|
for (Iterator<String> its = orderIds.iterator(); its.hasNext();) {
|
String orderId = its.next();
|
List<TaoBaoOrder> list = taoBaoOrderService.getTaoBaoOrderByOrderId(orderId);
|
startTimes[p] = TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss") - 1000L;
|
endTimes[p] = TimeUtil.convertToTimeTemp(list.get(0).getCreateTime(), "yyyy-MM-dd HH:mm:ss") + 1000L;
|
p++;
|
}
|
|
for (int i = 0; i < idsArray.size(); i++) {
|
updateRelationAndSpecialOrderJob.updateRelationAndSpecialOrder(startTimes[i], endTimes[i]);
|
updateOrderJob.updateOrder(startTimes[i], endTimes[i]);
|
}
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("更新成功"));
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("更新失败"));
|
e.printStackTrace();
|
}
|
}
|
|
@RequestMapping(value = "listTaoBaoWQOrder")
|
public void listTaoBaoWeiQuanOrder(String callback, String key, Integer pageIndex, PrintWriter out) {
|
try {
|
if (pageIndex == null || pageIndex < 0) {
|
pageIndex = 1;
|
}
|
List<TaoBaoWeiQuanOrder> orderList = null;
|
Long count = null;
|
if (!StringUtil.isNullOrEmpty(key)) {
|
orderList = taoBaoWeiQuanOrderService.listByOrderId(key);
|
count = (long) orderList.size();
|
} else {
|
orderList = taoBaoWeiQuanOrderService.listByState(null, pageIndex, Constant.PAGE_SIZE);
|
count = taoBaoWeiQuanOrderService.countByState(null);
|
}
|
|
int pageSize = Constant.PAGE_SIZE;
|
|
int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
|
PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
|
|
Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
|
@Override
|
public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
|
if (value == null) {
|
return new JsonPrimitive("");
|
} else {
|
return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss"));
|
}
|
}
|
}).create();
|
|
JSONObject data = new JSONObject();
|
data.put("pe", pe);
|
data.put("result_list", gson.toJson(orderList));
|
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("查询失败"));
|
e.printStackTrace();
|
}
|
}
|
|
}
|