天气
This commit is contained in:
parent
29d6893ab8
commit
14192a0c7d
@ -0,0 +1,299 @@
|
||||
package com.zhgd.xmgl.modules.basicdata.controller;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.zhgd.annotation.OperLog;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.SystemUser;
|
||||
import com.zhgd.xmgl.modules.basicdata.service.ISystemUserService;
|
||||
import com.zhgd.xmgl.security.entity.UserInfo;
|
||||
import com.zhgd.xmgl.security.util.SecurityUtils;
|
||||
import com.zhgd.xmgl.util.PageUtil;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.zhgd.jeecg.common.api.vo.Result;
|
||||
import com.zhgd.jeecg.common.system.query.QueryGenerator;
|
||||
import com.zhgd.jeecg.common.util.oConvertUtils;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.Weather;
|
||||
import com.zhgd.xmgl.modules.basicdata.service.IWeatherService;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
|
||||
import org.jeecgframework.poi.excel.entity.ExportParams;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import springfox.documentation.annotations.ApiIgnore;
|
||||
|
||||
|
||||
/**
|
||||
* @Title: Controller
|
||||
* @Description: 天气信息
|
||||
* @author: pengj
|
||||
* @date: 2024-08-23
|
||||
* @version: V1.0
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/xmgl/weather")
|
||||
@Slf4j
|
||||
@Api(tags = "天气信息管理")
|
||||
public class WeatherController {
|
||||
@Autowired
|
||||
private IWeatherService weatherService;
|
||||
|
||||
@Autowired
|
||||
private ISystemUserService systemUserService;
|
||||
|
||||
|
||||
@OperLog(operModul = "天气信息管理", operType = "查询最近一周的天气", operDesc = "查询最近一周的天气")
|
||||
@ApiOperation(value = "查询天气-周", notes = "查询天气-周", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "projectSn", value = "项目SN", paramType = "body", dataType = "String")
|
||||
@PostMapping(value = "/getWeatherData")
|
||||
public Result<List<Weather>> getWeatherData(@RequestBody Weather weather) {
|
||||
QueryWrapper<Weather> queryWrapper = QueryGenerator.initQueryWrapper(weather);
|
||||
queryWrapper.lambda().ge(Weather::getDate, new Date());
|
||||
queryWrapper.lambda().le(Weather::getDate, DateUtil.offsetDay(new Date(), 7));
|
||||
return Result.success(weatherService.list(queryWrapper));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "天气信息管理", operType = "分页查询", operDesc = "分页列表查询天气信息信息")
|
||||
@ApiOperation(value = " 分页列表查询天气信息信息", notes = "分页列表查询天气信息信息", httpMethod = "POST")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "pageNo", value = "页数", paramType = "body", required = true, defaultValue = "1", dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "pageSize", value = "每页条数", paramType = "body", required = true, defaultValue = "10", dataType = "Integer")
|
||||
})
|
||||
@PostMapping(value = "/page")
|
||||
public Result<IPage<Weather>> queryPageList(@ApiIgnore @RequestBody Map<String, Object> map) {
|
||||
QueryWrapper<Weather> queryWrapper = QueryGenerator.initPageQueryWrapper(Weather.class, map);
|
||||
Page<Weather> page = PageUtil.getPage(map);
|
||||
IPage<Weather> pageList = weatherService.page(page, queryWrapper);
|
||||
return Result.success(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
*
|
||||
* @param weather
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "天气信息管理", operType = "列表查询", operDesc = "列表查询天气信息信息")
|
||||
@ApiOperation(value = " 列表查询天气信息信息", notes = "列表查询天气信息信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/list")
|
||||
public Result<List<Weather>> queryList(@RequestBody Weather weather) {
|
||||
QueryWrapper<Weather> queryWrapper = QueryGenerator.initQueryWrapper(weather);
|
||||
List<Weather> list = weatherService.list(queryWrapper);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param weather
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "天气信息管理", operType = "新增", operDesc = "添加天气信息信息")
|
||||
@ApiOperation(value = " 添加天气信息信息", notes = "添加天气信息信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/add")
|
||||
public Result<Object> add(@RequestBody Weather weather) {
|
||||
weatherService.save(weather);
|
||||
return Result.success("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param weather
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "天气信息管理", operType = "修改", operDesc = "编辑天气信息信息")
|
||||
@ApiOperation(value = "编辑天气信息信息", notes = "编辑天气信息信息", httpMethod = "POST")
|
||||
@PostMapping(value = "/edit")
|
||||
public Result<Weather> edit(@RequestBody Weather weather) {
|
||||
Result<Weather> result = new Result<Weather>();
|
||||
Weather weatherEntity = weatherService.getById(weather.getId());
|
||||
if (weatherEntity == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = weatherService.updateById(weather);
|
||||
if (ok) {
|
||||
result.success("修改成功!");
|
||||
} else {
|
||||
result.success("操作失败!");
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "天气信息管理", operType = "删除", operDesc = "删除天气信息信息")
|
||||
@ApiOperation(value = "删除天气信息信息", notes = "删除天气信息信息", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "id", value = "天气信息ID", paramType = "body", required = true, dataType = "Integer")
|
||||
@PostMapping(value = "/delete")
|
||||
public Result<Weather> delete(@RequestBody Weather weather) {
|
||||
Result<Weather> result = new Result<Weather>();
|
||||
Weather weatherEntity = weatherService.getById(weather.getId());
|
||||
if (weatherEntity == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
boolean ok = weatherService.removeById(weather.getId());
|
||||
if (ok) {
|
||||
result.success("删除成功!");
|
||||
} else {
|
||||
result.success("操作失败!");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "天气信息管理", operType = "批量删除", operDesc = "批量删除天气信息信息")
|
||||
@ApiOperation(value = "批量删除天气信息信息", notes = "批量删除天气信息信息", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "ids", value = "天气信息ID字符串", paramType = "body", required = true, dataType = "String")
|
||||
@PostMapping(value = "/deleteBatch")
|
||||
public Result<Weather> deleteBatch(@ApiIgnore @RequestBody Map<String, Object> map) {
|
||||
Result<Weather> result = new Result<Weather>();
|
||||
String ids = MapUtils.getString(map, "ids");
|
||||
if (ids == null || "".equals(ids.trim())) {
|
||||
result.error500("参数不识别!");
|
||||
} else {
|
||||
this.weatherService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
result.success("删除成功!");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@OperLog(operModul = "天气信息管理", operType = "查询", operDesc = "通过id查询天气信息信息")
|
||||
@ApiOperation(value = "通过id查询天气信息信息", notes = "通过id查询天气信息信息", httpMethod = "POST")
|
||||
@ApiImplicitParam(name = "id", value = "天气信息ID", paramType = "body", required = true, dataType = "Integer")
|
||||
@PostMapping(value = "/queryById")
|
||||
public Result<Weather> queryById(@ApiIgnore @RequestBody Map<String, Object> map) {
|
||||
Result<Weather> result = new Result<Weather>();
|
||||
Weather weather = weatherService.getById(MapUtils.getString(map, "id"));
|
||||
if (weather == null) {
|
||||
result.error500("未找到对应实体");
|
||||
} else {
|
||||
result.setResult(weather);
|
||||
result.setSuccess(true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出excel
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
*/
|
||||
@ApiOperation(value = "导出excel天气信息信息", notes = "导出excel天气信息信息", httpMethod = "POST")
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, HttpServletResponse response) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<Weather> queryWrapper = null;
|
||||
try {
|
||||
String paramsStr = request.getParameter("paramsStr");
|
||||
if (oConvertUtils.isNotEmpty(paramsStr)) {
|
||||
String deString = URLDecoder.decode(paramsStr, "UTF-8");
|
||||
Weather weather = JSON.parseObject(deString, Weather.class);
|
||||
queryWrapper = QueryGenerator.initQueryWrapper(weather, request.getParameterMap());
|
||||
}
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Step.2 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
List<Weather> pageList = weatherService.list(queryWrapper);
|
||||
//导出文件名称
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "天气信息列表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, Weather.class);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("天气信息列表数据", "导出人:Jeecg", "导出信息"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, pageList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过excel导入数据
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value = "通过excel导入天气信息信息", notes = "通过excel导入天气信息信息", httpMethod = "POST")
|
||||
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
UserInfo user = SecurityUtils.getUser();
|
||||
SystemUser systemUser = systemUserService.getById(user.getUserId());
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
MultipartFile file = entity.getValue();// 获取上传文件对象
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<Weather> listWeathers = ExcelImportUtil.importExcel(file.getInputStream(), Weather.class, params);
|
||||
for (Weather weatherExcel : listWeathers) {
|
||||
weatherExcel.setUpdateTime(new Date());
|
||||
weatherExcel.setProjectSn(systemUser.getSn());
|
||||
weatherService.save(weatherExcel);
|
||||
}
|
||||
return Result.ok("文件导入成功!数据行数:" + listWeathers.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return Result.error("文件导入失败!");
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.ok("文件导入失败!");
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,95 @@
|
||||
package com.zhgd.xmgl.modules.basicdata.entity;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.jeecgframework.poi.excel.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
/**
|
||||
* @Description: 天气信息
|
||||
* @author: pengj
|
||||
* @date: 2024-08-23
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Data
|
||||
@TableName("weather")
|
||||
@ApiModel(value = "Weather实体类", description = "Weather")
|
||||
public class Weather implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 天气ID
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty(value = "天气ID")
|
||||
private Long id;
|
||||
/**
|
||||
* 预报日期
|
||||
*/
|
||||
@Excel(name = "预报日期", width = 15, format = "yyyy-MM-dd")
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@ApiModelProperty(value = "预报日期")
|
||||
private Date date;
|
||||
/**
|
||||
* 白天温度(高温)
|
||||
*/
|
||||
@Excel(name = "白天温度(高温)", width = 15)
|
||||
@ApiModelProperty(value = "白天温度(高温)")
|
||||
private String temDay;
|
||||
/**
|
||||
* 城市名称
|
||||
*/
|
||||
@Excel(name = "城市名称", width = 15)
|
||||
@ApiModelProperty(value = "城市名称")
|
||||
private String city;
|
||||
/**
|
||||
* 白天温度(低温)
|
||||
*/
|
||||
@Excel(name = "白天温度(低温)", width = 15)
|
||||
@ApiModelProperty(value = "白天温度(低温)")
|
||||
private String temNight;
|
||||
/**
|
||||
* 天气情况
|
||||
*/
|
||||
@Excel(name = "天气情况", width = 15)
|
||||
@ApiModelProperty(value = "天气情况")
|
||||
private String wea;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@ApiModelProperty(value = "更新时间")
|
||||
private Date updateTime;
|
||||
/**
|
||||
* 天气对应图标固定9种类型(您也可以根据wea字段自己处理):
|
||||
* xue、lei、shachen、wu、bingbao、yun、yu、yin、qing
|
||||
*/
|
||||
@Excel(name = "天气对应图标固定9种类型", width = 15)
|
||||
@ApiModelProperty(value = "天气对应图标固定9种类型(您也可以根据wea字段自己处理):xue、lei、shachen、wu、bingbao、yun、yu、yin、qing")
|
||||
private String weaImg;
|
||||
/**
|
||||
* 风力等级
|
||||
*/
|
||||
@Excel(name = "风力等级", width = 15)
|
||||
@ApiModelProperty(value = "风力等级")
|
||||
private Double winSpeed;
|
||||
/**
|
||||
* 风向
|
||||
*/
|
||||
@Excel(name = "风向", width = 15)
|
||||
@ApiModelProperty(value = "风向")
|
||||
private String win;
|
||||
/**
|
||||
* 项目SN
|
||||
*/
|
||||
@ApiModelProperty(value = "项目SN")
|
||||
private String projectSn;
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.zhgd.xmgl.modules.basicdata.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.Weather;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @Description: 天气信息
|
||||
* @author: pengj
|
||||
* @date: 2024-08-23
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Mapper
|
||||
public interface WeatherMapper extends BaseMapper<Weather> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.zhgd.xmgl.modules.basicdata.mapper.WeatherMapper">
|
||||
|
||||
</mapper>
|
||||
@ -0,0 +1,14 @@
|
||||
package com.zhgd.xmgl.modules.basicdata.service;
|
||||
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.Weather;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
* @Description: 天气信息
|
||||
* @author: pengj
|
||||
* @date: 2024-08-23
|
||||
* @version: V1.0
|
||||
*/
|
||||
public interface IWeatherService extends IService<Weather> {
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.zhgd.xmgl.modules.basicdata.service.impl;
|
||||
|
||||
import com.zhgd.xmgl.modules.basicdata.entity.Weather;
|
||||
import com.zhgd.xmgl.modules.basicdata.mapper.WeatherMapper;
|
||||
import com.zhgd.xmgl.modules.basicdata.service.IWeatherService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
|
||||
/**
|
||||
* @Description: 天气信息
|
||||
* @author: pengj
|
||||
* @date: 2024-08-23
|
||||
* @version: V1.0
|
||||
*/
|
||||
@Service
|
||||
public class WeatherServiceImpl extends ServiceImpl<WeatherMapper, Weather> implements IWeatherService {
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user