package com.ruoyi.interfaces.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping(value = "/context")
public class ContextController extends BaseController {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @ApiOperation("添加关注")
    @GetMapping("/clickNum")
    public AjaxResult insertAttention(@RequestParam String ip, @RequestParam String city) {
        if (StringUtils.isBlank(ip) || StringUtils.isBlank(city)) {
            return AjaxResult.error();
        }
        if (city.contains("市")) {
            city = city.replace("市", "");
        }

        String sql = "INSERT INTO `view_log`(`ip`, `city`, `tm`) VALUES (?, ?, ?);";
        jdbcTemplate.update(sql, ip, city, new Date());
        return AjaxResult.success();
    }
}
