package com.sys.controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sys.dao.SysShareMapper;
import com.sys.model.SysShare;

import java.io.*;

@Controller
@RequestMapping("sysShare")
public class SysShareController {
	
	@Autowired
	SysShareMapper sysShareMapper;
	
	@RequestMapping("share")
    protected void share(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer total = 10;
        String type = req.getParameter("type");
        if(type==null && "".equals(type)){
        	type = "yulin";
        }
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();
        SysShare sysShare = sysShareMapper.getCountByType(type);
        String getCount = sysShare.getShareCount();
        total = Integer.parseInt(getCount);
        sysShareMapper.updateCountByType(type, (total+1)+"");
        out.write("{\"total\":\""+total+"\"}");
        out.flush();
        out.close();
    }
}
