yanghui
2022-11-17 a7e51f7d5d77a0019723c5dcf1a65599a4bf2b7b
flower_city/src/main/java/com/dg/core/controller/CommonController.java
@@ -2,6 +2,8 @@
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.dg.core.CorsConfig;
import com.dg.core.ResultData;
import com.dg.core.db.gen.AjaxResult;
@@ -17,6 +19,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -24,10 +27,7 @@
import javax.annotation.Resource;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.*;
import static com.dg.core.file.FileTypeUploadUtils.assertAllowed;
@@ -41,7 +41,6 @@
  @Autowired
  private CorsConfig corsConfig;
  // FTP 登录用户名
@@ -59,6 +58,9 @@
  @Value("${ftp.url}")
  private String url;
    @Resource
    RedisTemplate<String, Object> redisTemplate;
  @RequestMapping("/hello")
//  @Authorization
@@ -72,8 +74,7 @@
   */
  @ApiOperation("文件上传接口(通用)")
  @PostMapping("/uploads")
  public ResultData uploadFiles(List<MultipartFile> files) throws Exception
  {
    public ResultData uploadFiles(List<MultipartFile> files) throws Exception {
    List<String> urls = new ArrayList<String>();
    List<String> fileNames = new ArrayList<String>();
    List<String> originalFilenames = new ArrayList<String>();
@@ -105,14 +106,12 @@
  }
  /**
   * 通用上传请求(单个)
   */
  @ApiOperation("文件上传接口(通用)")
  @PostMapping("/upload")
  public ResultData uploadFile(MultipartFile file) throws Exception
  {
    public ResultData uploadFile(MultipartFile file) throws Exception {
    List<String> urls = new ArrayList<String>();
    List<String> fileNames = new ArrayList<String>();
    List<String> originalFilenames = new ArrayList<String>();
@@ -146,8 +145,7 @@
   */
  @ApiOperation("判断当前时间是否是工作日,格式为“20221016”,不传默认为今天")
  @GetMapping("/isWeekday")
  public ResultData isWeekday(@RequestParam(value = "dateTime",required = false) String dateTime)
  {
    public ResultData isWeekday(@RequestParam(value = "dateTime", required = false) String dateTime) {
      if (dateTime==null){
        Date date = new Date();
        SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMdd");
@@ -159,5 +157,21 @@
         return success("工作日");
  }
    /**
     * 获取天气默认为攀枝花
     */
    @ApiOperation("获取天气默认为攀枝花")
    @GetMapping("/getWeather")
    public ResultData getWeather(@RequestParam(value = "code", required = false) String code) {
        TestDate td = new TestDate();
        Map weather;
        if (code == null) {//默认为攀枝花 则从redis上获取redis上定时任务15分钟获取一次天气
            HashMap weather1 = (HashMap) redisTemplate.opsForValue().get("weather");
            return ResultData.success(weather1.get("lives"));
        } else {
            return ResultData.success(td.getWeather(code));
        }
    }
}