package com.yeshi.fanli.controller.admin;
|
|
import java.io.PrintWriter;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.yeshi.utils.JsonUtil;
|
|
import com.yeshi.fanli.entity.admin.HistorySearchAdmin;
|
import com.yeshi.fanli.entity.admin.ScanHistoryAdmin;
|
import com.yeshi.fanli.service.inter.order.OrderService;
|
import com.yeshi.fanli.service.inter.user.HistorySearchService;
|
import com.yeshi.fanli.service.inter.user.ScanHistoryService;
|
import com.yeshi.fanli.service.inter.user.UserInfoService;
|
import com.yeshi.fanli.util.TimeUtil;
|
import com.yeshi.fanli.util.Utils;
|
|
import net.sf.json.JSONObject;
|
|
@Controller
|
@RequestMapping("admin/new/api/v1/data")
|
public class DataAdminController {
|
|
@Resource
|
private OrderService orderService;
|
|
@Resource
|
private UserInfoService userInfoService;
|
|
@Resource
|
private ScanHistoryService scanHistoryService;
|
|
@Resource
|
private HistorySearchService historySearchService;
|
|
private final static int TOPSUM = 100;
|
private final static String AWEEK = "1";
|
private final static String HALFMONTH = "2";
|
private final static String AMONTH = "3";
|
private final static String THREEMONTH = "4";
|
|
@RequestMapping(value = "getGoodsBrowseList", method = RequestMethod.POST)
|
public void getGoodsBrowseList(String type, PrintWriter out) {
|
Map<String, Integer> map = null;
|
if (AWEEK.equals(type)) {
|
map = scanHistoryService.getDataCountByDate(7);
|
} else if (HALFMONTH.equals(type)) {
|
map = scanHistoryService.getDataCountByDate(15);
|
} else if (AMONTH.equals(type)) {
|
int days = TimeUtil.getDayOfMonth();
|
map = scanHistoryService.getDataCountByDate(days);
|
} else {
|
map = scanHistoryService.getDataCountByMonth(3, new Date());
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
}
|
|
@RequestMapping(value = "goodsBrowseListByTime", method = RequestMethod.POST)
|
public void goodsBrowseListByTime(String startTime, String endTime, PrintWriter out) {
|
Map<String, Integer> map = null;
|
try {
|
Date startDate = TimeUtil.parse(startTime);
|
Date endDate = TimeUtil.parse(endTime);
|
Date curDate = new Date();
|
if (startDate.getTime() - curDate.getTime() > 0 || endDate.getTime() - curDate.getTime() > 0) {
|
out.print(JsonUtil.loadFalseResult("起止时间不能大于当前时间"));
|
return;
|
}
|
if (curDate.getTime() - endDate.getTime() < 0) {
|
endDate = curDate;
|
endTime = TimeUtil.getSimpleDate(endDate);
|
}
|
int months = Utils.countMonths(startTime, endTime);
|
if (months < 2) {
|
int countDay = Utils.countDay(startTime, endTime);
|
map = scanHistoryService.getDataCountByDate(countDay, endTime);
|
} else {
|
map = scanHistoryService.getDataCountByMonth(months + 1, endDate);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@RequestMapping(value = "getRegistUserList", method = RequestMethod.POST)
|
public void getRegistUserList(String type, PrintWriter out) {
|
Map<String, Integer> map = null;
|
Date date = new Date();
|
if (AWEEK.equals(type)) {
|
map = userInfoService.getnewUserByDate(7, date);
|
} else if (HALFMONTH.equals(type)) {
|
map = userInfoService.getnewUserByDate(15, date);
|
} else if (AMONTH.equals(type)) {
|
int days = TimeUtil.getDayOfMonth();
|
map = userInfoService.getnewUserByDate(days, date);
|
} else {
|
map = userInfoService.getnewUserByMonth(3, date);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
}
|
|
@RequestMapping(value = "registUserListByTime", method = RequestMethod.POST)
|
public void registUserListByTime(String startTime, String endTime, PrintWriter out) {
|
Map<String, Integer> map = null;
|
try {
|
Date startDate = TimeUtil.parse(startTime);
|
Date endDate = TimeUtil.parse(endTime);
|
Date curDate = new Date();
|
if (startDate.getTime() - curDate.getTime() > 0 || endDate.getTime() - curDate.getTime() > 0) {
|
out.print(JsonUtil.loadFalseResult("起止时间不能大于当前时间"));
|
return;
|
}
|
if (curDate.getTime() - endDate.getTime() < 0) {
|
endDate = curDate;
|
endTime = TimeUtil.getSimpleDate(endDate);
|
}
|
int months = Utils.countMonths(startTime, endTime);
|
if (months < 2) {
|
int countDay = Utils.countDay(startTime, endTime);
|
map = userInfoService.getnewUserByDate(countDay, endDate);
|
} else {
|
map = userInfoService.getnewUserByMonth(months + 1, endDate);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@RequestMapping(value = "getUserTotalList", method = RequestMethod.POST)
|
public void getUserTotalList(String type, PrintWriter out) {
|
Map<String, Integer> map = null;
|
Date date = new Date();
|
if (AWEEK.equals(type)) {
|
map = userInfoService.getUserTotalByDate(7, date);
|
} else if (HALFMONTH.equals(type)) {
|
map = userInfoService.getUserTotalByDate(15, date);
|
} else if (AMONTH.equals(type)) {
|
int days = TimeUtil.getDayOfMonth();
|
map = userInfoService.getUserTotalByDate(days, date);
|
} else {
|
map = userInfoService.getUserTotalByMonth(3, date);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
}
|
|
@RequestMapping(value = "userListByTime", method = RequestMethod.POST)
|
public void userListByTime(String startTime, String endTime, PrintWriter out) {
|
Map<String, Integer> map = null;
|
try {
|
Date startDate = TimeUtil.parse(startTime);
|
Date endDate = TimeUtil.parse(endTime);
|
Date curDate = new Date();
|
if (startDate.getTime() - curDate.getTime() > 0 || endDate.getTime() - curDate.getTime() > 0) {
|
out.print(JsonUtil.loadFalseResult("起止时间不能大于当前时间"));
|
return;
|
}
|
if (curDate.getTime() - endDate.getTime() < 0) {
|
endDate = curDate;
|
endTime = TimeUtil.getSimpleDate(endDate);
|
}
|
int months = Utils.countMonths(startTime, endTime);
|
if (months < 2) {
|
int countDay = Utils.countDay(startTime, endTime);
|
map = userInfoService.getUserTotalByDate(countDay, endDate);
|
} else {
|
map = userInfoService.getUserTotalByMonth(months + 1, endDate);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@RequestMapping(value = "getnewOrderList", method = RequestMethod.POST)
|
public void getOrderList(String type, PrintWriter out) {
|
Map<String, Integer> map = null;
|
Date date = new Date();
|
if (AWEEK.equals(type)) {
|
map = orderService.getnewOrderByDate(7, date);
|
} else if (HALFMONTH.equals(type)) {
|
map = orderService.getnewOrderByDate(15, date);
|
} else if (AMONTH.equals(type)) {
|
int days = TimeUtil.getDayOfMonth();
|
map = orderService.getnewOrderByDate(days, date);
|
} else {
|
map = orderService.getnewOrderByMonth(3, date);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
}
|
|
@RequestMapping(value = "orderListByTime", method = RequestMethod.POST)
|
public void orderListByTime(String startTime, String endTime, PrintWriter out) {
|
Map<String, Integer> map = null;
|
try {
|
Date startDate = TimeUtil.parse(startTime);
|
Date endDate = TimeUtil.parse(endTime);
|
Date curDate = new Date();
|
if (startDate.getTime() - curDate.getTime() > 0 || endDate.getTime() - curDate.getTime() > 0) {
|
out.print(JsonUtil.loadFalseResult("起止时间不能大于当前时间"));
|
return;
|
}
|
if (curDate.getTime() - endDate.getTime() < 0) {
|
endDate = curDate;
|
endTime = TimeUtil.getSimpleDate(endDate);
|
}
|
int months = Utils.countMonths(startTime, endTime);
|
if (months < 2) {
|
int countDay = Utils.countDay(startTime, endTime);
|
map = orderService.getnewOrderByDate(countDay, endDate);
|
} else {
|
map = orderService.getnewOrderByMonth(months + 1, endDate);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@RequestMapping(value = "getOrderTotalList", method = RequestMethod.POST)
|
public void getOrderTotalList(String type, PrintWriter out) {
|
Map<String, Integer> map = null;
|
Date date = new Date();
|
if (AWEEK.equals(type)) {
|
map = orderService.getOrderTotalByDate(7, date);
|
} else if (HALFMONTH.equals(type)) {
|
map = orderService.getOrderTotalByDate(15, date);
|
} else if (AMONTH.equals(type)) {
|
int days = TimeUtil.getDayOfMonth();
|
map = orderService.getOrderTotalByDate(days, date);
|
} else {
|
map = orderService.getOrderTotalByMonth(3, date);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
}
|
|
@RequestMapping(value = "orderTotalListByTime", method = RequestMethod.POST)
|
public void orderTotalListByTime(String startTime, String endTime, PrintWriter out) {
|
Map<String, Integer> map = null;
|
try {
|
Date startDate = TimeUtil.parse(startTime);
|
Date endDate = TimeUtil.parse(endTime);
|
Date curDate = new Date();
|
if (startDate.getTime() - curDate.getTime() > 0 || endDate.getTime() - curDate.getTime() > 0) {
|
out.print(JsonUtil.loadFalseResult("起止时间不能大于当前时间"));
|
return;
|
}
|
if (curDate.getTime() - endDate.getTime() < 0) {
|
endDate = curDate;
|
endTime = TimeUtil.getSimpleDate(endDate);
|
}
|
int months = Utils.countMonths(startTime, endTime);
|
if (months < 2) {
|
int countDay = Utils.countDay(startTime, endTime);
|
map = orderService.getOrderTotalByDate(countDay, endDate);
|
} else {
|
map = orderService.getOrderTotalByMonth(months + 1, endDate);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@RequestMapping(value = "getSearchTotalList", method = RequestMethod.POST)
|
public void getSearchTotalList(String type, PrintWriter out) {
|
Map<String, Integer> map = null;
|
Date date = new Date();
|
if (AWEEK.equals(type)) {
|
map = historySearchService.getSearchTotalByDate(7, date);
|
} else if (HALFMONTH.equals(type)) {
|
map = historySearchService.getSearchTotalByDate(15, date);
|
} else if (AMONTH.equals(type)) {
|
int days = TimeUtil.getDayOfMonth();
|
map = historySearchService.getSearchTotalByDate(days, date);
|
} else {
|
map = historySearchService.getSearchTotalByMonth(3, date);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
}
|
|
@RequestMapping(value = "searchTotalListByTime", method = RequestMethod.POST)
|
public void searchTotalListByTime(String startTime, String endTime, PrintWriter out) {
|
Map<String, Integer> map = null;
|
try {
|
Date startDate = TimeUtil.parse(startTime);
|
Date endDate = TimeUtil.parse(endTime);
|
Date curDate = new Date();
|
if (startDate.getTime() - curDate.getTime() > 0 || endDate.getTime() - curDate.getTime() > 0) {
|
out.print(JsonUtil.loadFalseResult("起止时间不能大于当前时间"));
|
return;
|
}
|
if (curDate.getTime() - endDate.getTime() < 0) {
|
endDate = curDate;
|
endTime = TimeUtil.getSimpleDate(endDate);
|
}
|
int months = Utils.countMonths(startTime, endTime);
|
if (months < 2) {
|
int countDay = Utils.countDay(startTime, endTime);
|
map = historySearchService.getSearchTotalByDate(countDay, endDate);
|
} else {
|
map = historySearchService.getSearchTotalByMonth(months + 1, endDate);
|
}
|
out.print(JsonUtil.loadTrueResult(Utils.sort(map)));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
@RequestMapping(value = "getSearchRankList", method = RequestMethod.POST)
|
public void getSearchRankList(String type, PrintWriter out) {
|
List<HistorySearchAdmin> historySearchList = null;
|
Date date = new Date();
|
if (AWEEK.equals(type)) {
|
historySearchList = historySearchService.getSearchRankByDate(7, date);
|
} else if (HALFMONTH.equals(type)) {
|
historySearchList = historySearchService.getSearchRankByDate(15, date);
|
} else if (AMONTH.equals(type)) {
|
int days = TimeUtil.getDayOfMonth();
|
historySearchList = historySearchService.getSearchRankByDate(days, date);
|
} else {
|
historySearchList = historySearchService.getSearchRankByDate(90, date);
|
}
|
out.print(JsonUtil.loadTrueResult(historySearchList));
|
}
|
|
@RequestMapping(value = "searchRankListByTime", method = RequestMethod.POST)
|
public void searchRankListByTime(String startTime, String endTime, PrintWriter out) {
|
List<HistorySearchAdmin> historySearchList = null;
|
try {
|
Date startDate = TimeUtil.parse(startTime);
|
Date endDate = TimeUtil.parse(endTime);
|
Date curDate = new Date();
|
if (startDate.getTime() - curDate.getTime() > 0 || endDate.getTime() - curDate.getTime() > 0) {
|
out.print(JsonUtil.loadFalseResult("起止时间不能大于当前时间"));
|
return;
|
}
|
if (curDate.getTime() - endDate.getTime() < 0) {
|
endDate = curDate;
|
endTime = TimeUtil.getSimpleDate(endDate);
|
}
|
int days = Utils.countDay(startTime, endTime);
|
historySearchList = historySearchService.getSearchRankByDate(days, endDate);
|
out.print(JsonUtil.loadTrueResult(historySearchList));
|
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(e.getMessage()));
|
}
|
}
|
|
}
|