StatisticsController.java 1.62 KB
package com.example.controller;

import com.example.mapper.ShareLogMapper;
import com.example.support.model.MessageEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by JA on 17/7/3.
 */
@RequestMapping("/kmr/statistics")
@RestController
public class StatisticsController {

	@Autowired
	private ShareLogMapper shareLogMapper;

	private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	@RequestMapping
	public MessageEntity statistics(HttpServletRequest request,@RequestParam(required = false)String time) {
		MessageEntity.Builder builder = new MessageEntity.Builder(request);
		if(StringUtils.isBlank(time)){
			Date date = new Date();
			time = this.sdf.format(date);
		}
		String startDate = time + " 00:00:00";
		String endDate = time + " 23:59:59";
		int pv = this.shareLogMapper.findPVByDay(startDate, endDate);
		int uv = this.shareLogMapper.findUVByDay(startDate, endDate);
		int share = this.shareLogMapper.findShareByDay(startDate, endDate);
		int img = this.shareLogMapper.findImgByDay(startDate, endDate);
		Map<String,Object> map = new HashMap<>();
		map.put("pv",pv);
		map.put("uv",uv);
		map.put("share",share);
		map.put("img",img);
		return builder.success(true).code("2000").content(map).create();
	}

}