package com.rongwei.savecheck.controller;

import com.rongwei.rwcommon.base.R;
import com.rongwei.sfcommon.sys.service.impl.JfCommonServiceImpl;
import com.rongwei.sfcommon.utils.CommonUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
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;

/**
 * CommonController class
 *
 * @author XH
 * @date 2021/01/08
 */
@RestController
@RequestMapping("/common-util")
@Slf4j
public class CommonUtilController {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private JfCommonServiceImpl jfCommonService;

    @GetMapping("/week-for-year")
    public R weekForYear(@RequestParam("date") @DateTimeFormat(pattern = "yyyy-MM-dd") Date date,
                         @RequestParam("returnLastWeek") String returnLastWeek) {
        logger.info("begin get week for year");
        R r = new R();
        if (date == null) {
            r.setCode("200");
            r.putData(CommonUtil.getWeekForYear(Boolean.parseBoolean(returnLastWeek)));
            return r;
        }
        r.setCode("200");
        r.putData(CommonUtil.getWeekForYear(date, Boolean.parseBoolean(returnLastWeek)));
        return r;
    }

    @GetMapping("/gps")
    public R getLocationIdFormBDApi(@RequestParam(name = "address") String address){
        return jfCommonService.getLocationIdFormBDApi(address);
    }
}
