|
@@ -1,6 +1,9 @@
|
|
|
package com.happy.action;
|
|
package com.happy.action;
|
|
|
|
|
|
|
|
import com.happy.Model.UserVisits;
|
|
import com.happy.Model.UserVisits;
|
|
|
|
|
+import com.happy.Until.DateUtil;
|
|
|
|
|
+import com.happy.Until.Enum.VisitsEnum;
|
|
|
|
|
+import com.happy.Until.Func;
|
|
|
import com.happy.Until.ResUtil;
|
|
import com.happy.Until.ResUtil;
|
|
|
import com.happy.dao.UserVisitsDao;
|
|
import com.happy.dao.UserVisitsDao;
|
|
|
import com.happy.dto.IDCBookStatusEto;
|
|
import com.happy.dto.IDCBookStatusEto;
|
|
@@ -12,18 +15,24 @@ import com.opensymphony.xwork2.ActionSupport;
|
|
|
import net.sf.json.JSONObject;
|
|
import net.sf.json.JSONObject;
|
|
|
import org.apache.struts2.ServletActionContext;
|
|
import org.apache.struts2.ServletActionContext;
|
|
|
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
|
|
+import org.omg.CORBA.PUBLIC_MEMBER;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
+import static com.happy.Until.Enum.VisitsEnum.今日;
|
|
|
|
|
+
|
|
|
public class IDCAction extends ActionSupport implements ServletRequestAware {
|
|
public class IDCAction extends ActionSupport implements ServletRequestAware {
|
|
|
|
|
|
|
|
private HttpServletRequest request;
|
|
private HttpServletRequest request;
|
|
|
public HttpServletResponse response;
|
|
public HttpServletResponse response;
|
|
|
|
|
|
|
|
- public Integer type;//1.今日 2.本月 3.本年
|
|
|
|
|
|
|
+ public Integer type;//1.今日 2.本月 3.本年 4.自定义时间
|
|
|
|
|
+ public String startTime; // 开始时间
|
|
|
|
|
+ public String endTime; // 结束时间
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
private IDCService idcService;
|
|
private IDCService idcService;
|
|
@@ -173,12 +182,13 @@ public class IDCAction extends ActionSupport implements ServletRequestAware {
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 访问量,今日访问量
|
|
* 访问量,今日访问量
|
|
|
|
|
+ * 返回数据
|
|
|
* todayCount, 今日访问量
|
|
* todayCount, 今日访问量
|
|
|
* yesterdayCount, 昨日访问量
|
|
* yesterdayCount, 昨日访问量
|
|
|
* compare 相对比
|
|
* compare 相对比
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String userVisits()
|
|
|
|
|
|
|
+ public String visitsToday()
|
|
|
{
|
|
{
|
|
|
JSONObject resultJson = new JSONObject();
|
|
JSONObject resultJson = new JSONObject();
|
|
|
UserVisits info = userVisitsDao.queryTodayUserVisits();
|
|
UserVisits info = userVisitsDao.queryTodayUserVisits();
|
|
@@ -196,5 +206,77 @@ public class IDCAction extends ActionSupport implements ServletRequestAware {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 访问量趋势 今日、本周、本月
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public String visitsDiyQuery(){
|
|
|
|
|
+ JSONObject resultJson = new JSONObject();
|
|
|
|
|
+ List list = new ArrayList();
|
|
|
|
|
+ try {
|
|
|
|
|
+ switch (VisitsEnum.getEunmBykey(type)){
|
|
|
|
|
+ case 今日:
|
|
|
|
|
+ list = getTodayInfo();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 本周:
|
|
|
|
|
+ list = getWeekInfo();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 本月:
|
|
|
|
|
+ list = getMonthInfo();
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 自定义:
|
|
|
|
|
+ list = getDiyInfo(startTime, endTime);
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 状态异常:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ resultJson.put("message", "查询成功");
|
|
|
|
|
+ resultJson.put("code", 200);
|
|
|
|
|
+ resultJson.put("data", list);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ resultJson.put("message", e.getMessage());
|
|
|
|
|
+ resultJson.put("code", 400);
|
|
|
|
|
+ resultJson.put("data", list);
|
|
|
|
|
+ ResUtil.writeJson(ServletActionContext.getResponse(), resultJson.toString());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 自定义时间查询
|
|
|
|
|
+ private List getDiyInfo(String startTime,String endTime) throws Exception
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!(DateUtil.isDateStr(startTime,true) && DateUtil.isDateStr(endTime,true)))
|
|
|
|
|
+ throw new RuntimeException("请输入正确的时间");
|
|
|
|
|
+
|
|
|
|
|
+ if (DateUtil.getDayDiff(startTime,endTime) > 31)
|
|
|
|
|
+ throw new RuntimeException("查询天数仅31天之内");
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ return userVisitsDao.queryVisitsByDiyTime(startTime,endTime);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 今日
|
|
|
|
|
+ private List getTodayInfo()
|
|
|
|
|
+ {
|
|
|
|
|
+ String sql = " DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'), INTERVAL seq DAY) = DATE_FORMAT(NOW(),'%Y-%m-%d') ";
|
|
|
|
|
+ return userVisitsDao.queryVisitsBySql(sql);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 本周
|
|
|
|
|
+ private List getWeekInfo()
|
|
|
|
|
+ {
|
|
|
|
|
+ String sql = "DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'), INTERVAL seq DAY) >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY) \n" +
|
|
|
|
|
+ "AND DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'), INTERVAL seq DAY) <= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE())-6 DAY)";
|
|
|
|
|
+ return userVisitsDao.queryVisitsBySql(sql);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 本月
|
|
|
|
|
+ private List getMonthInfo()
|
|
|
|
|
+ {
|
|
|
|
|
+ String sql = "DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'), INTERVAL seq DAY) >= DATE_ADD(CURDATE(),interval -day(CURDATE())+1 day)\n" +
|
|
|
|
|
+ "AND DATE_ADD(DATE_FORMAT(NOW(),'%Y-%m-%d'), INTERVAL seq DAY) <= LAST_DAY(CURDATE())";
|
|
|
|
|
+ return userVisitsDao.queryVisitsBySql(sql);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
}
|
|
}
|